|
From: John M M. <jo...@us...> - 2002-09-27 19:57:55
|
Update of /cvsroot/squeak/squeak/platforms/Mac OS/plugins/SocketPlugin
In directory usw-pr-cvs1:/tmp/cvs-serv13569/squeak/platforms/Mac OS/plugins/SocketPlugin
Modified Files:
sqMacNetwork.c
Log Message:
3.2.8b8 Add support for IP_ADD/DROPMEMBERSHIP for joining UDP broadcasting groups. Also allow binding to port 0.
Index: sqMacNetwork.c
===================================================================
RCS file: /cvsroot/squeak/squeak/platforms/Mac OS/plugins/SocketPlugin/sqMacNetwork.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** sqMacNetwork.c 18 Dec 2001 21:24:52 -0000 1.2
--- sqMacNetwork.c 27 Sep 2002 19:57:51 -0000 1.3
***************
*** 62,65 ****
--- 62,66 ----
v1.3.11 Nov 11th 2000, JMM extra buffer for server version
v1.3.12 Jan 2001, Karl Goiser Carbon changes
+ v1.3.13 Sept 2002, JMM fixes for wildcard port binding, and IP_ADD_MEMBERSHIP logic
Notes beware semaphore's lurk for socket support. Three semaphores lives in Smalltalk, waiting for
***************
*** 306,309 ****
--- 307,311 ----
static UInt32 readBytesUDP(EPInfo* epi,InetAddress *fromAddress, int *moreFlag, char *buf,UInt32 adjustedBufSize);
static SInt32 lookupOptionName(EPInfo *epi, Boolean trueIfGet, char *aString, UInt32 value, SInt32 *result);
+ static OTResult SetEightByteOption(EPInfo* epi, Boolean trueIfGet, OTXTILevel level, OTXTIName name, char * value, SInt32 *result);
static OTResult SetFourByteOption(EPInfo* epi, Boolean trueIfGet, OTXTILevel level, OTXTIName name, UInt32 value, SInt32 *result);
static OTResult SetOneByteOption(EPInfo* epi, Boolean trueIfGet, OTXTILevel level, OTXTIName name, UInt32 value, SInt32 *result);
***************
*** 766,770 ****
if (s->socketType == TCPSocketType) {
DoBind(epi,0,(InetPort) port,TCPListenerSocketType,1);
! if (epi->localAddress.fPort != port) {//We die if we don't get the port we want
sqSocketDestroy(s);
interpreterProxy->success(false);
--- 768,772 ----
if (s->socketType == TCPSocketType) {
DoBind(epi,0,(InetPort) port,TCPListenerSocketType,1);
! if (port != 0 && epi->localAddress.fPort != port) {//We die if we don't get the port we want
sqSocketDestroy(s);
interpreterProxy->success(false);
***************
*** 799,803 ****
epi = (EPInfo *) s->privateSocketPtr;
DoBind(epi,0,(InetPort) port,TCPListenerSocketType,(OTQLen) backlogSize);
! if (epi->localAddress.fPort != port) {//The port we wanted must match, otherwise we die
sqSocketDestroy(s);
interpreterProxy->success(false);
--- 801,805 ----
epi = (EPInfo *) s->privateSocketPtr;
DoBind(epi,0,(InetPort) port,TCPListenerSocketType,(OTQLen) backlogSize);
! if (port != 0 && epi->localAddress.fPort != port) {//The port we wanted must match, otherwise we die
sqSocketDestroy(s);
interpreterProxy->success(false);
***************
*** 2352,2359 ****
OTMemcpy(optionValue,(char *) optionValueT,optionValueSize);
optionValue[optionValueSize] = 0x00;
! CopyCStringToPascal(optionValue,(unsigned char *) optionValue);
! StringToNum((ConstStr255Param) optionValue,&anInteger);
!
! error = lookupOptionName(epi, false, (char *) &optionName, anInteger,(long *) result);
return error;
}
--- 2354,2364 ----
OTMemcpy(optionValue,(char *) optionValueT,optionValueSize);
optionValue[optionValueSize] = 0x00;
! if (optionValueSize == 8) {
! error = lookupOptionName(epi, false, (char *) &optionName, (long) &optionValue ,(long *) result);
! } else {
! CopyCStringToPascal(optionValue,(unsigned char *) optionValue);
! StringToNum((ConstStr255Param) optionValue,&anInteger);
! error = lookupOptionName(epi, false, (char *) &optionName, anInteger,(long *) result);
! }
return error;
}
***************
*** 2416,2426 ****
if (strcmp("IP_MULTICAST_TTL",aString)==0) {return SetOneByteOption(epi,trueIfGet,INET_IP,kIP_MULTICAST_TTL,value,result);};
if (strcmp("IP_MULTICAST_LOOP",aString)==0) {return SetOneByteOption(epi,trueIfGet,INET_IP,kIP_MULTICAST_LOOP,value,result);};
! /* if (strcmp("IP_ADD_MEMBERSHIP",aString)==0) { return SetJMMByteOption(epi,trueIfGet,INET_IP,IP_ADD_MEMBERSHIP,value,result);};
! if (strcmp("IP_DROP_MEMBERSHIP",aString)==0) { return SetJMMByteOption(epi,trueIfGet,INET_IP,IP_DROP_MEMBERSHIP,value,result);};
! if (strcmp("IP_BROADCAST_IF",aString)==0) {return SetFourByteOption(epi,trueIfGet,INET_IP,IP_BROADCAST_IF,value,result);};
! if (strcmp("IP_RCVIFADDR",aString)==0) {return SetFourByteOption(epi,trueIfGet,INET_IP,IP_RCVIFADDR,value,result);}; */
*result = 0;
return -1;
}
--- 2421,2478 ----
if (strcmp("IP_MULTICAST_TTL",aString)==0) {return SetOneByteOption(epi,trueIfGet,INET_IP,kIP_MULTICAST_TTL,value,result);};
if (strcmp("IP_MULTICAST_LOOP",aString)==0) {return SetOneByteOption(epi,trueIfGet,INET_IP,kIP_MULTICAST_LOOP,value,result);};
! if (strcmp("IP_ADD_MEMBERSHIP",aString)==0) { return SetEightByteOption(epi,trueIfGet,INET_IP,kIP_ADD_MEMBERSHIP,(char *) value,result);};
! if (strcmp("IP_DROP_MEMBERSHIP",aString)==0) { return SetEightByteOption(epi,trueIfGet,INET_IP,kIP_DROP_MEMBERSHIP,(char *) value,result);};
! if (strcmp("IP_BROADCAST_IFNAME",aString)==0) {return SetFourByteOption(epi,trueIfGet,INET_IP,kIP_BROADCAST_IFNAME,value,result);};
! if (strcmp("IP_RCVIFADDR",aString)==0) {return SetFourByteOption(epi,trueIfGet,INET_IP,kIP_RCVIFADDR,value,result);};
*result = 0;
return -1;
+ }
+
+ static OTResult SetEightByteOption(EPInfo* epi,Boolean trueIfGet, OTXTILevel level, OTXTIName name, char * value, SInt32 *returnValue) {
+ OTResult err;
+ UInt8 optBuffer[kOTFourByteOptionSize+4];
+ TOption *option = (TOption *) &optBuffer;
+ TOptMgmt request;
+ TOptMgmt result;
+ Boolean isAsync=false;
+
+ /* Set up the option buffer to specify the option and value to set. */
+ option->len = kOTFourByteOptionSize+4;
+ option->level= level;
+ option->name = name;
+ option->status = 0;
+ if (!trueIfGet)
+ OTMemcpy(option->value,value,8);
+
+ /* Set up request parameter for OTOptionManagement */
+ request.opt.buf= (UInt8 *) option;
+ request.opt.len= sizeof(optBuffer);
+ request.opt.maxlen=sizeof(optBuffer);
+ request.flags = trueIfGet ? T_CURRENT : T_NEGOTIATE;
+
+ /* Set up reply parameter for OTOptionManagement. */
+ result.opt.buf = (UInt8 *) option;
+ result.opt.maxlen = sizeof(optBuffer);
+
+ if (OTIsSynchronous(epi->erf) == false) { // check whether ep sync or not
+ isAsync = true; // set flag if async
+ OTSetSynchronous(epi->erf); // set endpoint to sync
+ }
+
+
+ err = OTOptionManagement(epi->erf, &request, &result);
+
+ if (isAsync) // restore ep state
+ OTSetAsynchronous(epi->erf);
+
+ *returnValue = option->value[0];
+
+ if (err == noErr) {
+ if (option->status != T_SUCCESS)
+ err = option->status;
+ }
+
+ return (err);
}
|