Socket.st
changeset 2579 d70306ae12ac
parent 2551 6da1bc89b74a
child 2680 ff00563f0444
--- a/Socket.st	Wed Jul 20 20:00:08 2011 +0200
+++ b/Socket.st	Wed Jul 20 20:49:19 2011 +0200
@@ -65,7 +65,9 @@
 #include <errno.h>
 
 #ifdef WIN32
-# include <Ws2tcpip.h>
+# ifndef __VISUALC__
+#  include <Ws2tcpip.h>
+# endif
 #else
 # include <netinet/ip.h>
 #endif
@@ -2979,228 +2981,228 @@
     |ok|
 
     handle isNil ifTrue:[
-        ^ self errorNotOpen
+	^ self errorNotOpen
     ].
 
 %{  /* STACK: 32000 */
     OBJ fp = __INST(handle);
 
     if (fp != nil) {
-        SOCKET sock;
-        int opt = -1;
-        int level = -1;
-        int usize = -1;
-        int ret;
-        union u {
-            BOOL        u_bool;
-            int         u_int;
-            struct linger u_linger;
+	SOCKET sock;
+	int opt = -1;
+	int level = -1;
+	int usize = -1;
+	int ret;
+	union u {
+	    BOOL        u_bool;
+	    int         u_int;
+	    struct linger u_linger;
 # ifdef IP_ADD_MEMBERSHIP
-            struct ip_mreq      u_ip_mreq;
+	    struct ip_mreq      u_ip_mreq;
 # endif
-        } u;
-
-        sock = SOCKET_FROM_FILE_OBJECT(fp);
+	} u;
+
+	sock = SOCKET_FROM_FILE_OBJECT(fp);
 
 # ifdef IP_ADD_MEMBERSHIP
-        if (option == @symbol(IP_DROP_MEMBERSHIP)) {
-            opt = IP_DROP_MEMBERSHIP;
-            goto dropOrAdd;
-        }
-        if (option == @symbol(IP_ADD_MEMBERSHIP)) {
-            /* add membership to a multicast group */
-            opt = IP_ADD_MEMBERSHIP;
+	if (option == @symbol(IP_DROP_MEMBERSHIP)) {
+	    opt = IP_DROP_MEMBERSHIP;
+	    goto dropOrAdd;
+	}
+	if (option == @symbol(IP_ADD_MEMBERSHIP)) {
+	    /* add membership to a multicast group */
+	    opt = IP_ADD_MEMBERSHIP;
 dropOrAdd:
-            level = IPPROTO_IP;
-            usize = sizeof(u.u_ip_mreq);
-            if (__isByteArrayLike(arg1) && __isByteArrayLike(arg2)) {
-                memcpy(&u.u_ip_mreq.imr_multiaddr, __byteArrayVal(arg1), sizeof(u.u_ip_mreq.imr_multiaddr));
-                memcpy(&u.u_ip_mreq.imr_interface, __byteArrayVal(arg2), sizeof(u.u_ip_mreq.imr_interface));
-            }
-            else 
-                goto argError;
-        }
+	    level = IPPROTO_IP;
+	    usize = sizeof(u.u_ip_mreq);
+	    if (__isByteArrayLike(arg1) && __isByteArrayLike(arg2)) {
+		memcpy(&u.u_ip_mreq.imr_multiaddr, __byteArrayVal(arg1), sizeof(u.u_ip_mreq.imr_multiaddr));
+		memcpy(&u.u_ip_mreq.imr_interface, __byteArrayVal(arg2), sizeof(u.u_ip_mreq.imr_interface));
+	    }
+	    else
+		goto argError;
+	}
 # endif /* IP_ADD_MEMBERSHIP */
 
 # ifdef SO_BROADCAST
-        if (option == @symbol(SO_BROADCAST)) {
-            /* Enables transmission and receipt of broadcast messages on the socket. */
-            opt = SO_BROADCAST;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_BROADCAST)) {
+	    /* Enables transmission and receipt of broadcast messages on the socket. */
+	    opt = SO_BROADCAST;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_BROADCAST */
 
 # ifdef SO_CONDITIONAL
 #  if 0
-        if (option == @symbol(SO_CONDITIONAL)) {
-            /* Enables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called. */
-            opt = SO_CONDITIONAL;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_CONDITIONAL)) {
+	    /* Enables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called. */
+	    opt = SO_CONDITIONAL;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 #  endif
 # endif /* SO_CONDITIONAL */
 
 # ifdef SO_DEBUG
-        if (option == @symbol(SO_DEBUG)) {
-            /* Records debugging information. */
-            opt = SO_DEBUG;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_DEBUG)) {
+	    /* Records debugging information. */
+	    opt = SO_DEBUG;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_DEBUG */
 
 # ifdef SO_DONTLINGER
-        if (option == @symbol(SO_DONTLINGER)) {
-            /* Does not block close waiting for unsent data to be sent.
-               Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero. */
-            opt = SO_DONTLINGER;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_DONTLINGER)) {
+	    /* Does not block close waiting for unsent data to be sent.
+	       Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero. */
+	    opt = SO_DONTLINGER;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_DONTLINGER */
 
 # ifdef SO_DONTROUTE
-        if (option == @symbol(SO_DONTROUTE)) {
-            /* Does not route: sends directly to interface.
-               Succeeds but is ignored on AF_INET sockets;
-               fails on AF_INET6 sockets with WSAENOPROTOOPT.
-               Not supported on ATM sockets (results in an error). */
-            opt = SO_DONTROUTE;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_DONTROUTE)) {
+	    /* Does not route: sends directly to interface.
+	       Succeeds but is ignored on AF_INET sockets;
+	       fails on AF_INET6 sockets with WSAENOPROTOOPT.
+	       Not supported on ATM sockets (results in an error). */
+	    opt = SO_DONTROUTE;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_DONTROUTE */
 
 #if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
-        if (option == @symbol(TCP_NODELAY)) {
-            /* enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm) */
-            opt = TCP_NODELAY;
-            level = IPPROTO_TCP;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(TCP_NODELAY)) {
+	    /* enable/disable TCP_NODELAY (i.e. disable/enable the Nagle algorithm) */
+	    opt = TCP_NODELAY;
+	    level = IPPROTO_TCP;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* TCP_NODELAY */
 
 # ifdef SO_KEEPALIVE
-        if (option == @symbol(SO_KEEPALIVE)) {
-            /* Sends keep-alives. Not supported on ATM sockets (results in an error). */
-            opt = SO_KEEPALIVE;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_KEEPALIVE)) {
+	    /* Sends keep-alives. Not supported on ATM sockets (results in an error). */
+	    opt = SO_KEEPALIVE;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_KEEPALIVE */
 
 # ifdef SO_LINGER
-        if (option == @symbol(SO_LINGER)) {
-            /* Lingers on close if unsent data is present. */
-            opt = SO_LINGER;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_linger);
-            if (arg1 == true) u.u_linger.l_onoff = TRUE;
-            else if (arg1 == false) u.u_linger.l_onoff = FALSE;
-            else goto argError;
-            if (arg2 == nil) u.u_linger.l_linger = 0;
-            else if (__isSmallInteger(arg2))u.u_linger.l_linger = __intVal(arg2);
-            else goto argError;
-            DBGPRINTF(("SOCKET: SO_LINGER %d %d\n", u.u_linger.l_onoff, u.u_linger.l_linger));
-        }
+	if (option == @symbol(SO_LINGER)) {
+	    /* Lingers on close if unsent data is present. */
+	    opt = SO_LINGER;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_linger);
+	    if (arg1 == true) u.u_linger.l_onoff = TRUE;
+	    else if (arg1 == false) u.u_linger.l_onoff = FALSE;
+	    else goto argError;
+	    if (arg2 == nil) u.u_linger.l_linger = 0;
+	    else if (__isSmallInteger(arg2))u.u_linger.l_linger = __intVal(arg2);
+	    else goto argError;
+	    DBGPRINTF(("SOCKET: SO_LINGER %d %d\n", u.u_linger.l_onoff, u.u_linger.l_linger));
+	}
 # endif /* SO_LINGER */
 
 # ifdef SO_OOBINLINE
-        if (option == @symbol(SO_OOBINLINE)) {
-            /* Receives OOB data in the normal data stream. */
-            opt = SO_OOBINLINE;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_OOBINLINE)) {
+	    /* Receives OOB data in the normal data stream. */
+	    opt = SO_OOBINLINE;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_OOBINLINE */
 
 # ifdef SO_RCVBUF
-        if (option == @symbol(SO_RCVBUF)) {
-            /* Specifies the total per-socket buffer space reserved for receives.
-               This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
-            opt = SO_RCVBUF;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_int);
-            if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
-            else goto argError;
-        }
+	if (option == @symbol(SO_RCVBUF)) {
+	    /* Specifies the total per-socket buffer space reserved for receives.
+	       This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
+	    opt = SO_RCVBUF;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_int);
+	    if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
+	    else goto argError;
+	}
 # endif /* SO_RCVBUF */
 
 # ifdef SO_SNDBUF
-        if (option == @symbol(SO_SNDBUF)) {
-            /* Specifies the total per-socket buffer space reserved for sends.
-               This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
-            opt = SO_SNDBUF;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_int);
-            if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
-            else goto argError;
-        }
+	if (option == @symbol(SO_SNDBUF)) {
+	    /* Specifies the total per-socket buffer space reserved for sends.
+	       This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window. */
+	    opt = SO_SNDBUF;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_int);
+	    if (__isSmallInteger(arg1))u.u_int = __intVal(arg1);
+	    else goto argError;
+	}
 # endif /* SO_SNDBUF */
 
 # ifdef SO_REUSEADDR
-        if (option == @symbol(SO_REUSEADDR)) {
-            /* Allows the socket to be bound to an address that is already in use.  */
-            opt = SO_REUSEADDR;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_REUSEADDR)) {
+	    /* Allows the socket to be bound to an address that is already in use.  */
+	    opt = SO_REUSEADDR;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_OOBINLINE */
 
 # ifdef SO_EXCLUSIVEADDRUSE
-        if (option == @symbol(SO_EXCLUSIVEADDRUSE)) {
-            /* Enables a socket to be bound for exclusive access.
-               Does not require administrative privilege.  */
-            opt = SO_EXCLUSIVEADDRUSE;
-            level = SOL_SOCKET;
-            usize = sizeof(u.u_bool);
-            if (arg1 == true) u.u_bool = TRUE;
-            else if (arg1 == false) u.u_bool = FALSE;
-            else goto argError;
-        }
+	if (option == @symbol(SO_EXCLUSIVEADDRUSE)) {
+	    /* Enables a socket to be bound for exclusive access.
+	       Does not require administrative privilege.  */
+	    opt = SO_EXCLUSIVEADDRUSE;
+	    level = SOL_SOCKET;
+	    usize = sizeof(u.u_bool);
+	    if (arg1 == true) u.u_bool = TRUE;
+	    else if (arg1 == false) u.u_bool = FALSE;
+	    else goto argError;
+	}
 # endif /* SO_OOBINLINE */
 
-        if (usize == -1) goto argError;
-
-        ok = ( setsockopt( sock, level, opt, &u, usize) >= 0) ? true : false;
+	if (usize == -1) goto argError;
+
+	ok = ( setsockopt( sock, level, opt, &u, usize) >= 0) ? true : false;
     }
 argError: ;
 
 %}.
     ok isNil ifTrue:[
-        self primitiveFailed
+	self primitiveFailed
     ].
     ok ifFalse:[
-        'setsocketoption failed' infoPrintCR.
+	'setsocketoption failed' infoPrintCR.
     ].
 !
 
@@ -3991,9 +3993,9 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.260 2011-03-29 17:31:54 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.261 2011-07-20 18:49:19 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.260 2011-03-29 17:31:54 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.261 2011-07-20 18:49:19 cg Exp $'
 ! !