Socket.st
changeset 2465 54e32314a856
parent 2461 e095fca98779
child 2516 592619f82885
--- a/Socket.st	Tue Jul 13 14:16:28 2010 +0200
+++ b/Socket.st	Fri Jul 30 11:06:25 2010 +0200
@@ -1706,9 +1706,9 @@
      i.e. address must always be nil.
 
      The interpretation of portNrOrName depends on the domain:
-        inet domain uses (4byte) byteArray like internet numbers,
-        unix domain uses pathname strings,
-        others use whatever will come up in the future
+	inet domain uses (4byte) byteArray like internet numbers,
+	unix domain uses pathname strings,
+	others use whatever will come up in the future
 
      The reuse boolean argument controls if the SO_REUSEADDR socket option
      is to be set (to avoid the 'bind: address in use' error).
@@ -1717,37 +1717,37 @@
     |ok addr addrName domainClass error|
 
     handle isNil ifTrue:[
-        ^ self errorNotOpen
+	^ self errorNotOpen
     ].
 
     domainClass := self class socketAddressClassForDomain:domain.
     domainClass isNil ifTrue:[
-        ^ self error:'invalid (unsupported) domain'.
+	^ self error:'invalid (unsupported) domain'.
     ].
 
     hostOrPathNameOrSocketAddrOrNil isNil ifTrue:[
-        addr := domainClass anyHost.
+	addr := domainClass anyHost.
     ] ifFalse:[
-        (hostOrPathNameOrSocketAddrOrNil isKindOf:SocketAddress) ifTrue:[
-            addr := hostOrPathNameOrSocketAddrOrNil.
-        ] ifFalse:[
-            "backward compatibility: support for byteArray and string arg"
-            hostOrPathNameOrSocketAddrOrNil isString ifTrue:[
-                addr := domainClass hostName:hostOrPathNameOrSocketAddrOrNil.
-                addrName := hostOrPathNameOrSocketAddrOrNil.
-            ] ifFalse:[
-                hostOrPathNameOrSocketAddrOrNil isByteArray ifFalse:[
-                    ^ self error:'bad host (socketAddress) argument'
-                ].
-                addr := domainClass hostAddress:hostOrPathNameOrSocketAddrOrNil.
-            ].
-        ].
+	(hostOrPathNameOrSocketAddrOrNil isKindOf:SocketAddress) ifTrue:[
+	    addr := hostOrPathNameOrSocketAddrOrNil.
+	] ifFalse:[
+	    "backward compatibility: support for byteArray and string arg"
+	    hostOrPathNameOrSocketAddrOrNil isString ifTrue:[
+		addr := domainClass hostName:hostOrPathNameOrSocketAddrOrNil.
+		addrName := hostOrPathNameOrSocketAddrOrNil.
+	    ] ifFalse:[
+		hostOrPathNameOrSocketAddrOrNil isByteArray ifFalse:[
+		    ^ self error:'bad host (socketAddress) argument'
+		].
+		addr := domainClass hostAddress:hostOrPathNameOrSocketAddrOrNil.
+	    ].
+	].
     ].
     portNrOrNameOrNil notNil ifTrue:[
-        addr port:portNrOrNameOrNil.
+	addr port:portNrOrNameOrNil.
     ].
     (portNrOrNameOrNil isNil or:[portNrOrNameOrNil == 0]) ifTrue:[
-        addr := addr copy.
+	addr := addr copy.
     ].
     ok := false.
 
@@ -1761,53 +1761,53 @@
     int sockAddrOffs;
 
     if (! __isBytes(addr)) {
-        error = __mkSmallInteger(-1);
-        addr = nil;
-        goto getOutOfHere;
+	error = __mkSmallInteger(-1);
+	addr = nil;
+	goto getOutOfHere;
     }
     if (fp == nil) {
-        goto getOutOfHere;
+	goto getOutOfHere;
     }
 
     /* get the socket-address */
     {
-        int nIndex;
-        OBJ cls;
-
-        sockAddrOffs = 0;
-        if ((cls = __qClass(addr)) != @global(ByteArray))
-            sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-        nIndex = __qSize(addr) - OHDR_SIZE;
-        sockaddr_size = nIndex - sockAddrOffs;
-        if (sockaddr_size > sizeof(sa)) {
-            error=__mkSmallInteger(-2);
-            goto getOutOfHere;
-        }
-        memcpy(&sa, __byteArrayVal(addr) + sockAddrOffs, sockaddr_size);
+	int nIndex;
+	OBJ cls;
+
+	sockAddrOffs = 0;
+	if ((cls = __qClass(addr)) != @global(ByteArray))
+	    sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	nIndex = __qSize(addr) - OHDR_SIZE;
+	sockaddr_size = nIndex - sockAddrOffs;
+	if (sockaddr_size > sizeof(sa)) {
+	    error=__mkSmallInteger(-2);
+	    goto getOutOfHere;
+	}
+	memcpy(&sa, __byteArrayVal(addr) + sockAddrOffs, sockaddr_size);
     }
 
     sock = SOCKET_FROM_FILE_OBJECT(fp);
 
 # ifdef SO_REUSEADDR
     if (reuse == true) {
-        int on = 1;
-
-        if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
-            DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
-        }
+	int on = 1;
+
+	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
+	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
+	}
     }
 # endif /* SO_REUSEADDR */
 
 # ifdef BIND_BLOCKS
 #  ifdef DO_WRAP_CALLS
     do {
-        __threadErrno = 0;
-        ret = STX_WSA_NOINT_CALL3("bind", bind, sock, &sa, sockaddr_size);
+	__threadErrno = 0;
+	ret = STX_WSA_NOINT_CALL3("bind", bind, sock, &sa, sockaddr_size);
     } while ((ret < 0) && (__threadErrno == EINTR));
 #  else
     __BEGIN_INTERRUPTABLE__
     do {
-        ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
+	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
     } while ((ret < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
 #  endif
@@ -1815,41 +1815,41 @@
     ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
 # endif
     if (ret < 0) {
-        DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
-        error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        goto getOutOfHere;
+	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
+	error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	goto getOutOfHere;
     } else {
-        ok = true;
-
-        if (! __isSmallInteger(portNrOrNameOrNil)
-            || (portNrOrNameOrNil == __MKSMALLINT(0))) {
-            unsigned int alen = sockaddr_size;
-
-            /*
-             * anonymous port - get the actual portNr
-             */
-            if (getsockname(sock, (struct sockaddr *)&sa, &alen) < 0) {
+	ok = true;
+
+	if (! __isSmallInteger(portNrOrNameOrNil)
+	    || (portNrOrNameOrNil == __MKSMALLINT(0))) {
+	    unsigned int alen = sockaddr_size;
+
+	    /*
+	     * anonymous port - get the actual portNr
+	     */
+	    if (getsockname(sock, (struct sockaddr *)&sa, &alen) < 0) {
 # ifdef WIN32
-                errno = WSAGetLastError();
+		errno = WSAGetLastError();
 # endif
-                console_fprintf(stderr, "SOCKET: cannot get socketname: %d\n", errno);
-            }
-            memcpy(__byteArrayVal(addr) + sockAddrOffs, &sa, alen);
-        }
+		console_fprintf(stderr, "SOCKET: cannot get socketname: %d\n", errno);
+	    }
+	    memcpy(__byteArrayVal(addr) + sockAddrOffs, &sa, alen);
+	}
     }
 #endif /* NO_SOCKET */
 
 getOutOfHere: ;
 %}.
     ok ~~ true ifTrue:[
-        "maybe someone catches the error and binds to some other port..."
-        OpenError
-            raiseRequestWith:self
-            errorString:('cannot bind socket to port: <1p> address: <2p> (error=<3p>)'
-                                expandMacrosWith:portNrOrNameOrNil
-                                with:hostOrPathNameOrSocketAddrOrNil
-                                with:error).
-        ^ true.
+	"maybe someone catches the error and binds to some other port..."
+	OpenError
+	    raiseRequestWith:self
+	    errorString:('cannot bind socket to port: <1p> address: <2p> (error=<3p>)'
+				expandMacrosWith:portNrOrNameOrNil
+				with:hostOrPathNameOrSocketAddrOrNil
+				with:error).
+	^ true.
     ].
 
     port := addr port.
@@ -1858,8 +1858,8 @@
 
     "
      (Socket domain:#inet type:#stream)
-         bindTo:21
-         address:nil
+	 bindTo:21
+	 address:nil
     "
 !
 
@@ -1878,7 +1878,7 @@
      aNumber is the number of connect requests, that may be queued on the socket"
 
     handle isNil ifTrue:[
-        ^ self errorNotOpen
+	^ self errorNotOpen
     ].
 %{
 #ifndef NO_SOCKET
@@ -1887,8 +1887,8 @@
     int ret;
 
     if (! __isSmallInteger(aNumber)) {
-        DBGPRINTF(("SOCKET: invalid arg\n"));
-        RETURN (false);
+	DBGPRINTF(("SOCKET: invalid arg\n"));
+	RETURN (false);
     }
 
     sock = SOCKET_FROM_FILE_OBJECT(fp);
@@ -1896,13 +1896,13 @@
 #ifdef LISTEN_BLOCKS
 # ifdef DO_WRAP_CALLS
     do {
-        __threadErrno = 0;
-        ret = STX_WSA_NOINT_CALL2("listen", listen, sock, __intVal(aNumber));
+	__threadErrno = 0;
+	ret = STX_WSA_NOINT_CALL2("listen", listen, sock, __intVal(aNumber));
     } while ((ret < 0) && (__threadErrno == EINTR));
 # else
     __BEGIN_INTERRUPTABLE__
     do {
-        ret = listen(sock, __intVal(aNumber));
+	ret = listen(sock, __intVal(aNumber));
     } while ((ret < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
 # endif
@@ -1911,9 +1911,9 @@
 #endif
 
     if (ret < 0) {
-        DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
-        __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        RETURN (false);
+	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
+	__INST(lastErrorNumber) = __MKSMALLINT(errno);
+	RETURN (false);
     }
 #else
     RETURN (false);
@@ -1976,30 +1976,30 @@
     |isAsync err domainClass addr addrName|
 
     handle isNil ifTrue:[
-        ^ self errorNotOpen
+	^ self errorNotOpen
     ].
 
     (hostOrPathNameOrSocketAddr isKindOf:SocketAddress) ifTrue:[
-        addr := hostOrPathNameOrSocketAddr.
-        portNrOrNameOrNil notNil ifTrue:[
-            addr port:portNrOrNameOrNil.
-        ].
+	addr := hostOrPathNameOrSocketAddr.
+	portNrOrNameOrNil notNil ifTrue:[
+	    addr port:portNrOrNameOrNil.
+	].
     ] ifFalse:[
-        "backward compatibility: support for byteArray and string arg"
-        domainClass := self class socketAddressClassForDomain:domain.
-        domainClass isNil ifTrue:[
-            ^ self error:'invalid (unsupported) domain'.
-        ].
-
-        hostOrPathNameOrSocketAddr isString ifTrue:[
-            addr := domainClass hostName:hostOrPathNameOrSocketAddr serviceName:portNrOrNameOrNil type:#SOCK_STREAM.
-            addrName := hostOrPathNameOrSocketAddr.
-        ] ifFalse:[
-            hostOrPathNameOrSocketAddr isByteCollection ifFalse:[
-                ^ self error:'bad host (socketAddress) argument'
-            ].
-            addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
-        ].
+	"backward compatibility: support for byteArray and string arg"
+	domainClass := self class socketAddressClassForDomain:domain.
+	domainClass isNil ifTrue:[
+	    ^ self error:'invalid (unsupported) domain'.
+	].
+
+	hostOrPathNameOrSocketAddr isString ifTrue:[
+	    addr := domainClass hostName:hostOrPathNameOrSocketAddr serviceName:portNrOrNameOrNil type:#SOCK_STREAM.
+	    addrName := hostOrPathNameOrSocketAddr.
+	] ifFalse:[
+	    hostOrPathNameOrSocketAddr isByteCollection ifFalse:[
+		^ self error:'bad host (socketAddress) argument'
+	    ].
+	    addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
+	].
     ].
 
 %{  /* STACK: 100000 */
@@ -2014,24 +2014,24 @@
     int sockaddr_size;
 
     if (!__isNonNilObject(addr) || !__isBytes(addr)) {
-        DBGPRINTF(("SOCKET: invalid addrBytes\n"));
-        RETURN (false);
+	DBGPRINTF(("SOCKET: invalid addrBytes\n"));
+	RETURN (false);
     }
 
     {
-        int sockAddrOffs, nIndex;
-        OBJ cls;
-
-        sockAddrOffs = 0;
-        if ((cls = __qClass(addr)) != @global(ByteArray))
-            sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-        nIndex = __qSize(addr) - OHDR_SIZE;
-        sockaddr_size = nIndex - sockAddrOffs;
-        if (sockaddr_size > sizeof(sa)) {
-            console_fprintf(stderr, "Socket: bad socketAddr\n");
-            RETURN (false);
-        }
-        bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
+	int sockAddrOffs, nIndex;
+	OBJ cls;
+
+	sockAddrOffs = 0;
+	if ((cls = __qClass(addr)) != @global(ByteArray))
+	    sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	nIndex = __qSize(addr) - OHDR_SIZE;
+	sockaddr_size = nIndex - sockAddrOffs;
+	if (sockaddr_size > sizeof(sa)) {
+	    console_fprintf(stderr, "Socket: bad socketAddr\n");
+	    RETURN (false);
+	}
+	bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
     }
 
     sock = SOCKET_FROM_FILE_OBJECT(fp);
@@ -2054,60 +2054,60 @@
     /* __setWrapCallDebugging(1,1); */
 
     do {
-        DBGFPRINTF((stderr, "SOCKET: connect...\n"));
-        __threadErrno = 0;
-        ret = STX_WSA_NOINT_CALL3("connect", connect, sock, &sa, sockaddr_size);
-        DBGFPRINTF((stderr, "SOCKET: connect(%d) -> %d (%d)\n", sock, ret, __threadErrno));
+	DBGFPRINTF((stderr, "SOCKET: connect...\n"));
+	__threadErrno = 0;
+	ret = STX_WSA_NOINT_CALL3("connect", connect, sock, &sa, sockaddr_size);
+	DBGFPRINTF((stderr, "SOCKET: connect(%d) -> %d (%d)\n", sock, ret, __threadErrno));
     } while ((ret < 0) && (__threadErrno == EINTR));
     /* __setWrapCallDebugging(1,0); */
 # else
     __BEGIN_INTERRUPTABLE__
     do {
-        ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size);
+	ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size);
     } while ((ret < 0)
-             && ((errno == EINTR)
+	     && ((errno == EINTR)
 # ifdef EAGAIN
-                 || (errno == EAGAIN)
+		 || (errno == EAGAIN)
 # endif
-                ));
+		));
     __END_INTERRUPTABLE__
 #endif
 
     if (ret < 0) {
 # if defined(EINPROGRESS) || defined(EALREADY)
-        if (0
+	if (0
 #  ifdef EINPROGRESS
-            || (errno == EINPROGRESS)
+	    || (errno == EINPROGRESS)
 #  endif
 #  ifdef EALREADY
-            || (errno == EALREADY)
+	    || (errno == EALREADY)
 #  endif
-        ) {
-            /*
-             * This was a nonblocking operation that will take some time.
-             * Do a select on read to get informed when the operation is ready.
-             */
-            DBGFPRINTF((stderr, "SOCKET: isAsync is true\n"));
-            isAsync = true;
-        } else
+	) {
+	    /*
+	     * This was a nonblocking operation that will take some time.
+	     * Do a select on read to get informed when the operation is ready.
+	     */
+	    DBGFPRINTF((stderr, "SOCKET: isAsync is true\n"));
+	    isAsync = true;
+	} else
 # endif /* EINPROGRESS or EALREADY */
-        {
-            DBGFPRINTF((stderr, "SOCKET: connect failed ret=%d errno=%d __threadErrno=%d\n",
-                        ret, errno, __threadErrno ));
+	{
+	    DBGFPRINTF((stderr, "SOCKET: connect failed ret=%d errno=%d __threadErrno=%d\n",
+			ret, errno, __threadErrno ));
 # ifdef DUMP_ADDRESS
-            {
-                char *cp = (char *)(&sa);
-                int i;
-
-                console_printf("address data:\n");
-                for (i=0; i<sockaddr_size; i++) {
-                    console_printf(" %02x\n", *cp++);
-                }
-            }
+	    {
+		char *cp = (char *)(&sa);
+		int i;
+
+		console_printf("address data:\n");
+		for (i=0; i<sockaddr_size; i++) {
+		    console_printf(" %02x\n", *cp++);
+		}
+	    }
 # endif
-            err = __INST(lastErrorNumber) = __MKSMALLINT(errno);
-            RETURN (false);
-        }
+	    err = __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	    RETURN (false);
+	}
     }
 
 # if defined(O_NONBLOCK)
@@ -2121,16 +2121,16 @@
 # endif /* NO_SOCKET */
 %}.
     isAsync == true ifTrue:[
-        (self writeWaitWithTimeoutMs:timeout) ifTrue:[
-            "/ a timeout occured
-            "/ should I cancel the connect?
-            ^ false.
-        ].
-        err := self getSocketError.
-        err ~~ 0 ifTrue:[
-            lastErrorNumber := err.
-            ^ false.
-        ].
+	(self writeWaitWithTimeoutMs:timeout) ifTrue:[
+	    "/ a timeout occured
+	    "/ should I cancel the connect?
+	    ^ false.
+	].
+	err := self getSocketError.
+	err ~~ 0 ifTrue:[
+	    lastErrorNumber := err.
+	    ^ false.
+	].
     ].
 
 "/ Once we will raise an exception instead of returning false (and have to change some code above):
@@ -2141,9 +2141,9 @@
     peer := addr.
     peerName := addrName.
     port isNil ifTrue:[
-        "socket has not been explicitly bound,
-         after connect it has been bound implicitly - fetch the port"
-        port := self getFullSocketAddress port.
+	"socket has not been explicitly bound,
+	 after connect it has been bound implicitly - fetch the port"
+	port := self getFullSocketAddress port.
     ].
     ^ true
 
@@ -2177,67 +2177,67 @@
     OBJ fp = __INST(handle);
 
     if (fp != nil) {
-        SOCKET sock;
-        int objSize, offs;
-        int n;
-        char *extPtr;
-        unsigned char *buffer;
-        unsigned char *allocatedBuffer;
-        int flags = 0;
-
-        sock = SOCKET_FROM_FILE_OBJECT(fp);
-
-        if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
-        if (__isSmallInteger(nBytes)) {
-            if (__intVal(nBytes) < objSize) {
-                objSize = __intVal(nBytes);
-            }
-        }
+	SOCKET sock;
+	int objSize, offs;
+	int n;
+	char *extPtr;
+	unsigned char *buffer;
+	unsigned char *allocatedBuffer = NULL;
+	int flags = 0;
+
+	sock = SOCKET_FROM_FILE_OBJECT(fp);
+
+	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
+	if (__isSmallInteger(nBytes)) {
+	    if (__intVal(nBytes) < objSize) {
+		objSize = __intVal(nBytes);
+	    }
+	}
 
 # ifdef DO_WRAP_CALLS
-        if (extPtr) {
-            buffer = extPtr + offs;
-        } else {
-            allocatedBuffer = buffer = (char *)malloc(objSize);
-        }
-
-        do {
-            __threadErrno = 0;
-            n = STX_WSA_NOINT_CALL4("recv", recv, sock, buffer, objSize, flags);
-        } while ((n < 0) && (__threadErrno == EINTR));
-
-        if (allocatedBuffer) {
-            if (n > 0) {
-                bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
-            }
-            free(allocatedBuffer);
-        }
+	if (extPtr) {
+	    buffer = extPtr + offs;
+	} else {
+	    allocatedBuffer = buffer = (char *)malloc(objSize);
+	}
+
+	do {
+	    __threadErrno = 0;
+	    n = STX_WSA_NOINT_CALL4("recv", recv, sock, buffer, objSize, flags);
+	} while ((n < 0) && (__threadErrno == EINTR));
+
+	if (allocatedBuffer) {
+	    if (n > 0) {
+		bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
+	    }
+	    free(allocatedBuffer);
+	}
 # else
-        __BEGIN_INTERRUPTABLE__
-        do {
-            if (extPtr) {
-                n = recv(sock, extPtr + offs, objSize, flags);
-            } else {
-                n = recv(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags);
-            }
-        } while ((n < 0) && (errno == EINTR));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    if (extPtr) {
+		n = recv(sock, extPtr + offs, objSize, flags);
+	    } else {
+		n = recv(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags);
+	    }
+	} while ((n < 0) && (errno == EINTR));
+	__END_INTERRUPTABLE__
 # endif
 
-        if (n < 0) {
-            __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        }
-        nReceived = __MKSMALLINT(n);
+	if (n < 0) {
+	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	}
+	nReceived = __MKSMALLINT(n);
     }
 #endif
 bad: ;
 %}.
     nReceived notNil ifTrue:[
-        nReceived < 0 ifTrue:[
-            'Socket [warning]: ' infoPrint.
-            (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
-        ].
-        ^ nReceived
+	nReceived < 0 ifTrue:[
+	    'Socket [warning]: ' infoPrint.
+	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
+	].
+	^ nReceived
     ].
     "
      arrive here if you try to receive into an invalid buffer (i.e. not ByteArray-like)
@@ -2273,17 +2273,17 @@
 
     domainClass := self class socketAddressClassForDomain:domain.
     domainClass isNil ifTrue:[
-        ^ self error:'invalid (unsupported) domain'.
+	^ self error:'invalid (unsupported) domain'.
     ].
     (anAddressBuffer isKindOf:SocketAddress) ifTrue:[
-        anAddressBuffer class == domainClass ifFalse:[
-            ^ self error:'addressBuffer class mismatch (domain)'.
-        ].
-        addr := anAddressBuffer.
+	anAddressBuffer class == domainClass ifFalse:[
+	    ^ self error:'addressBuffer class mismatch (domain)'.
+	].
+	addr := anAddressBuffer.
     ] ifFalse:[
-        anAddressBuffer notNil ifTrue:[
-            addr := domainClass new.
-        ].
+	anAddressBuffer notNil ifTrue:[
+	    addr := domainClass new.
+	].
     ].
 
 %{
@@ -2291,101 +2291,101 @@
     OBJ fp = __INST(handle);
 
     if (fp != nil) {
-        SOCKET sock;
-        int objSize;
-        union sockaddr_u sa;
-        unsigned int alen = 0;
-        int n, offs;
-        int flags = 0;
-        char *extPtr;
-        unsigned char *allocatedBuffer = NULL;
-        unsigned char *buffer = NULL;
-
-        sock = SOCKET_FROM_FILE_OBJECT(fp);
-
-        if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
-        if (__isSmallInteger(nBytes)) {
-            if (__intVal(nBytes) < objSize) {
-                objSize = __intVal(nBytes);
-            }
-        }
+	SOCKET sock;
+	int objSize;
+	union sockaddr_u sa;
+	unsigned int alen = 0;
+	int n, offs;
+	int flags = 0;
+	char *extPtr;
+	unsigned char *allocatedBuffer = NULL;
+	unsigned char *buffer = NULL;
+
+	sock = SOCKET_FROM_FILE_OBJECT(fp);
+
+	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
+	if (__isSmallInteger(nBytes)) {
+	    if (__intVal(nBytes) < objSize) {
+		objSize = __intVal(nBytes);
+	    }
+	}
 # ifdef DO_WRAP_CALLS
-        if (extPtr) {
-            buffer = extPtr + offs;
-        } else {
-            allocatedBuffer = buffer = (char *)malloc(objSize);
-        }
-
-        do {
-            __threadErrno = 0;
-            alen = sizeof(sa);
-            n = STX_WSA_NOINT_CALL6("recvfrom", recvfrom, sock, buffer, objSize, flags, (struct sockaddr *)&sa, &alen);
-        } while ((n < 0) && (__threadErrno == EINTR));
-
-        if (allocatedBuffer) {
-            if (n > 0) {
-                bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
-            }
-            free(allocatedBuffer);
-        }
+	if (extPtr) {
+	    buffer = extPtr + offs;
+	} else {
+	    allocatedBuffer = buffer = (char *)malloc(objSize);
+	}
+
+	do {
+	    __threadErrno = 0;
+	    alen = sizeof(sa);
+	    n = STX_WSA_NOINT_CALL6("recvfrom", recvfrom, sock, buffer, objSize, flags, (struct sockaddr *)&sa, &alen);
+	} while ((n < 0) && (__threadErrno == EINTR));
+
+	if (allocatedBuffer) {
+	    if (n > 0) {
+		bcopy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, n);
+	    }
+	    free(allocatedBuffer);
+	}
 # else
-        __BEGIN_INTERRUPTABLE__
-        do {
-            alen = sizeof(sa);
-            if (extPtr) {
-                n = recvfrom(sock, extPtr + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
-            } else {
-                n = recvfrom(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
-            }
-        } while ((n < 0) && (errno == EINTR));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    alen = sizeof(sa);
+	    if (extPtr) {
+		n = recvfrom(sock, extPtr + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
+	    } else {
+		n = recvfrom(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, flags, (struct sockaddr *) &sa, &alen);
+	    }
+	} while ((n < 0) && (errno == EINTR));
+	__END_INTERRUPTABLE__
 # endif
 
-        if (n >= 0) {
-            if (__isNonNilObject(addr)) {
-                char *addrPtr;
-                OBJ oClass;
-                int nInstVars, nInstBytes, objSize;
-
-                oClass = __qClass(addr);
-                if (! __isBytes(addr) )
-                    goto bad;
-                nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-                nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
-                objSize = __qSize(addr) - nInstBytes;
-                addrPtr = (char *)__InstPtr(addr) + nInstBytes;
-                if (objSize < alen)
-                    goto bad;
-
-                /*
-                 * extract the datagrams address
-                 */
-                bcopy((char *)&sa, addrPtr, alen);
-                addrLen = __MKSMALLINT(alen);
-            }
-        }
-        if (n < 0) {
-            __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        }
-        nReceived = __MKSMALLINT(n);
+	if (n >= 0) {
+	    if (__isNonNilObject(addr)) {
+		char *addrPtr;
+		OBJ oClass;
+		int nInstVars, nInstBytes, objSize;
+
+		oClass = __qClass(addr);
+		if (! __isBytes(addr) )
+		    goto bad;
+		nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+		nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
+		objSize = __qSize(addr) - nInstBytes;
+		addrPtr = (char *)__InstPtr(addr) + nInstBytes;
+		if (objSize < alen)
+		    goto bad;
+
+		/*
+		 * extract the datagrams address
+		 */
+		bcopy((char *)&sa, addrPtr, alen);
+		addrLen = __MKSMALLINT(alen);
+	    }
+	}
+	if (n < 0) {
+	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	}
+	nReceived = __MKSMALLINT(n);
     }
 #endif
 bad: ;
 %}.
     nReceived notNil ifTrue:[
-        nReceived < 0 ifTrue:[
-            'Socket [warning]: ' infoPrint.
-            (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
-        ].
-        addrLen notNil ifTrue:[
-            (addr == anAddressBuffer) ifFalse:[
-                self obsoleteFeatureWarning:'please use a socketAddress argument'.
-
-                " can be a ByteArray for backward compatibility "
-                anAddressBuffer replaceFrom:1 to:addrLen with:(addr hostAddress).
-            ].
-        ].
-        ^ nReceived
+	nReceived < 0 ifTrue:[
+	    'Socket [warning]: ' infoPrint.
+	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
+	].
+	addrLen notNil ifTrue:[
+	    (addr == anAddressBuffer) ifFalse:[
+		self obsoleteFeatureWarning:'please use a socketAddress argument'.
+
+		" can be a ByteArray for backward compatibility "
+		anAddressBuffer replaceFrom:1 to:addrLen with:(addr hostAddress).
+	    ].
+	].
+	^ nReceived
     ].
     "
      arrive here if you try to receive into an invalid buffer
@@ -2413,63 +2413,63 @@
     if ((fp != nil)
      && __isSmallInteger(startIndex)
      && __isSmallInteger(nBytes)) {
-        SOCKET sock;
-        int objSize;
-        int n;
-        char *extPtr;
-        int _flags = 0;
-        int offs;
-        unsigned long norder;
-        unsigned char *buffer;
-        unsigned char *allocatedBuffer;
-
-        _flags = __longIntVal(flags);
-
-        sock = SOCKET_FROM_FILE_OBJECT(fp);
-
-        if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
-        if (__isSmallInteger(nBytes)) {
-            if (__intVal(nBytes) < objSize) {
-                objSize = __intVal(nBytes);
-            }
-        }
+	SOCKET sock;
+	int objSize;
+	int n;
+	char *extPtr;
+	int _flags = 0;
+	int offs;
+	unsigned long norder;
+	unsigned char *buffer;
+	unsigned char *allocatedBuffer = NULL;
+
+	_flags = __longIntVal(flags);
+
+	sock = SOCKET_FROM_FILE_OBJECT(fp);
+
+	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
+	if (__isSmallInteger(nBytes)) {
+	    if (__intVal(nBytes) < objSize) {
+		objSize = __intVal(nBytes);
+	    }
+	}
 
 # ifdef DGRAM_DEBUG
-        console_printf("sending %d bytes ...\n", nBytes);
+	console_printf("sending %d bytes ...\n", nBytes);
 # endif
 
 #ifdef DO_WRAP_CALLS
-        if (extPtr) {
-            buffer = extPtr + offs;
-        } else {
-            allocatedBuffer = buffer = (char *)malloc(objSize);
-            bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
-        }
-
-        do {
-            __threadErrno = 0;
-            n = STX_WSA_NOINT_CALL4("send", send, sock, buffer, objSize, _flags);
-        } while ((n < 0) && (__threadErrno == EINTR));
-
-        if (allocatedBuffer) {
-            free(allocatedBuffer);
-        }
+	if (extPtr) {
+	    buffer = extPtr + offs;
+	} else {
+	    allocatedBuffer = buffer = (char *)malloc(objSize);
+	    bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
+	}
+
+	do {
+	    __threadErrno = 0;
+	    n = STX_WSA_NOINT_CALL4("send", send, sock, buffer, objSize, _flags);
+	} while ((n < 0) && (__threadErrno == EINTR));
+
+	if (allocatedBuffer) {
+	    free(allocatedBuffer);
+	}
 #else
-        __BEGIN_INTERRUPTABLE__
-        do {
-            if (extPtr) {
-                n = send(sock, extPtr + offs, objSize, _flags);
-            } else {
-                n = send(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags);
-            }
-        } while ((n < 0) && (errno == EINTR));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    if (extPtr) {
+		n = send(sock, extPtr + offs, objSize, _flags);
+	    } else {
+		n = send(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags);
+	    }
+	} while ((n < 0) && (errno == EINTR));
+	__END_INTERRUPTABLE__
 #endif
 
-        if (n < 0) {
-            __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        }
-        RETURN (__MKSMALLINT(n));
+	if (n < 0) {
+	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	}
+	RETURN (__MKSMALLINT(n));
     }
 #endif
 bad: ;
@@ -2520,16 +2520,16 @@
 
     domainClass := self class socketAddressClassForDomain:domain.
     domainClass isNil ifTrue:[
-        ^ self error:'invalid (unsupported) domain'.
+	^ self error:'invalid (unsupported) domain'.
     ].
 
     (anAddressBuffer isKindOf:SocketAddress) ifTrue:[
-        addr := anAddressBuffer.
+	addr := anAddressBuffer.
     ] ifFalse:[
-        anAddressBuffer isByteArray ifFalse:[
-            ^ self error:'bad socketAddress argument'
-        ].
-        addr := domainClass hostAddress:anAddressBuffer.
+	anAddressBuffer isByteArray ifFalse:[
+	    ^ self error:'bad socketAddress argument'
+	].
+	addr := domainClass hostAddress:anAddressBuffer.
     ].
 %{
 #ifndef NO_SOCKET
@@ -2538,82 +2538,82 @@
     if ((fp != nil)
      && __isSmallInteger(startIndex)
      && __isSmallInteger(nBytes)) {
-        SOCKET sock;
-        int objSize;
-        struct sockaddr *sockaddr_ptr;
-        union sockaddr_u sa;
-        int alen = 0;
-        int sockAddrOffs, sockaddr_size;
-        int n;
-        char *extPtr;
-        int _flags = 0;
-        int offs;
-        unsigned long norder;
-        unsigned char *buffer;
-        unsigned char *allocatedBuffer;
-
-        _flags = __longIntVal(flags);
-        sock = SOCKET_FROM_FILE_OBJECT(fp);
-
-        if (! __isBytes(addr)) {
-            sockaddr_size = 0;
-            sockaddr_ptr = (struct sockaddr *)0;
-        } else {
-            int nIndex;
-            OBJ cls;
-
-            sockAddrOffs = 0;
-            if ((cls = __qClass(addr)) != @global(ByteArray))
-                sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-            nIndex = __qSize(addr) - OHDR_SIZE;
-            sockaddr_size = nIndex - sockAddrOffs;
-            if (sockaddr_size > sizeof(sa)) {
-                console_fprintf(stderr, "Socket [warning]: bad socketAddr\n");
-                goto bad;
-            }
-            bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
-            sockaddr_ptr = (struct sockaddr *)(&sa);
-        }
-
-        if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
-        if (__isSmallInteger(nBytes)) {
-            if (__intVal(nBytes) < objSize) {
-                objSize = __intVal(nBytes);
-            }
-        }
+	SOCKET sock;
+	int objSize;
+	struct sockaddr *sockaddr_ptr;
+	union sockaddr_u sa;
+	int alen = 0;
+	int sockAddrOffs, sockaddr_size;
+	int n;
+	char *extPtr;
+	int _flags = 0;
+	int offs;
+	unsigned long norder;
+	unsigned char *buffer;
+	unsigned char *allocatedBuffer = NULL;
+
+	_flags = __longIntVal(flags);
+	sock = SOCKET_FROM_FILE_OBJECT(fp);
+
+	if (! __isBytes(addr)) {
+	    sockaddr_size = 0;
+	    sockaddr_ptr = (struct sockaddr *)0;
+	} else {
+	    int nIndex;
+	    OBJ cls;
+
+	    sockAddrOffs = 0;
+	    if ((cls = __qClass(addr)) != @global(ByteArray))
+		sockAddrOffs += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	    nIndex = __qSize(addr) - OHDR_SIZE;
+	    sockaddr_size = nIndex - sockAddrOffs;
+	    if (sockaddr_size > sizeof(sa)) {
+		console_fprintf(stderr, "Socket [warning]: bad socketAddr\n");
+		goto bad;
+	    }
+	    bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
+	    sockaddr_ptr = (struct sockaddr *)(&sa);
+	}
+
+	if (! setupBufferParameters(aDataBuffer, startIndex, &extPtr, &offs, &objSize)) goto bad;
+	if (__isSmallInteger(nBytes)) {
+	    if (__intVal(nBytes) < objSize) {
+		objSize = __intVal(nBytes);
+	    }
+	}
 
 #ifdef DO_WRAP_CALLS
-        if (extPtr) {
-            buffer = extPtr + offs;
-        } else {
-            allocatedBuffer = buffer = (char *)malloc(objSize);
-            bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
-        }
-
-        do {
-            __threadErrno = 0;
-            n = STX_WSA_NOINT_CALL6("sendto", sendto, sock, buffer, objSize, _flags, sockaddr_ptr, sockaddr_size);
-        } while ((n < 0) && (__threadErrno == EINTR));
-
-        if (allocatedBuffer) {
-            free(allocatedBuffer);
-        }
+	if (extPtr) {
+	    buffer = extPtr + offs;
+	} else {
+	    allocatedBuffer = buffer = (char *)malloc(objSize);
+	    bcopy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, objSize);
+	}
+
+	do {
+	    __threadErrno = 0;
+	    n = STX_WSA_NOINT_CALL6("sendto", sendto, sock, buffer, objSize, _flags, sockaddr_ptr, sockaddr_size);
+	} while ((n < 0) && (__threadErrno == EINTR));
+
+	if (allocatedBuffer) {
+	    free(allocatedBuffer);
+	}
 #else
-        __BEGIN_INTERRUPTABLE__
-        do {
-            if (extPtr) {
-                n = sendto(sock, extPtr + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
-            } else {
-                n = sendto(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
-            }
-        } while ((n < 0) && (errno == EINTR));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    if (extPtr) {
+		n = sendto(sock, extPtr + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
+	    } else {
+		n = sendto(sock, (char *)__InstPtr(aDataBuffer) + offs, objSize, _flags, sockaddr_ptr, sockaddr_size);
+	    }
+	} while ((n < 0) && (errno == EINTR));
+	__END_INTERRUPTABLE__
 #endif
 
-        if (n < 0) {
-            __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        }
-        RETURN (__MKSMALLINT(n));
+	if (n < 0) {
+	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	}
+	RETURN (__MKSMALLINT(n));
     }
 #endif
 bad: ;
@@ -2638,50 +2638,50 @@
 
     t = __INST(handle);
     if (t != nil) {
-        FILE *fp;
-        SOCKET sock;
-        int fd;
-
-        __INST(handle) = nil;
-        fp = __FILEVal(t);
-        fd = fileno(fp);
-        sock = SOCKET_FROM_FD(fd);
+	FILE *fp;
+	SOCKET sock;
+	int fd;
+
+	__INST(handle) = nil;
+	fp = __FILEVal(t);
+	fd = fileno(fp);
+	sock = SOCKET_FROM_FD(fd);
 
 # ifdef DO_WRAP_CALLS
-        { int ret;
-        /*__setWrapCallDebugging(1,1); */
-
-          do {
-            __threadErrno = 0;
-            ret = STX_C_NOINT_CALL1("fclose", fclose, fp);
-          } while ((ret < 0) && (__threadErrno == EINTR));
+	{ int ret;
+	/*__setWrapCallDebugging(1,1); */
+
+	  do {
+	    __threadErrno = 0;
+	    ret = STX_C_NOINT_CALL1("fclose", fclose, fp);
+	  } while ((ret < 0) && (__threadErrno == EINTR));
 
 #  ifdef WIN32
-          do {
-            __threadErrno = 0;
-            ret = STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
-          } while ((ret < 0) && (__threadErrno == EINTR));
-          closesocket(sock);
+	  do {
+	    __threadErrno = 0;
+	    ret = STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
+	  } while ((ret < 0) && (__threadErrno == EINTR));
+	  closesocket(sock);
 #  endif
-        /*__setWrapCallDebugging(1,0);*/
-        }
+	/*__setWrapCallDebugging(1,0);*/
+	}
 # else /* !DO_WRAP_CALLS */
 
-        DBGFPRINTF((stderr, "SOCKET: fflush %x (%d %d)\n", fp, fileno(fp), sock));
-        fflush(fp);
+	DBGFPRINTF((stderr, "SOCKET: fflush %x (%d %d)\n", fp, fileno(fp), sock));
+	fflush(fp);
 
 #  if defined(CLOSESOCKET_BEFORE_FCLOSE)
-        DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock));
-        closesocket(sock);
+	DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock));
+	closesocket(sock);
 #  endif
-        if ((@global(FileOpenTrace) == true) || __debugging__) {
-            console_fprintf(stderr, "SOCKET: fclose %x (%d %d)\n", fp, fileno(fp), sock);
-        }
-        fclose(fp);
+	if ((@global(FileOpenTrace) == true) || __debugging__) {
+	    console_fprintf(stderr, "SOCKET: fclose %x (%d %d)\n", fp, fileno(fp), sock);
+	}
+	fclose(fp);
 
 #  if defined(CLOSESOCKET_AFTER_FCLOSE)
-        DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock));
-        closesocket(sock);
+	DBGFPRINTF((stderr, "SOCKET: closesocket (%d)\n", sock));
+	closesocket(sock);
 #  endif
 
 # endif /* !DO_WRAP_CALLS */
@@ -2792,22 +2792,22 @@
     |serverSocketFd addr addrLen domainClass|
 
     handle notNil ifTrue:[
-        ^ self errorAlreadyOpen
+	^ self errorAlreadyOpen
     ].
 
     domain := aSocket domain.
     socketType := aSocket type.
     serverSocketFd := aSocket fileDescriptor.
     serverSocketFd isNil ifTrue:[
-        ^ self error:'invalid server socket'
+	^ self error:'invalid server socket'
     ].
     (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
-        ^ self error:'invalid server socket'
+	^ self error:'invalid server socket'
     ].
 
     domainClass := self class socketAddressClassForDomain:domain.
     domainClass isNil ifTrue:[
-        ^ self error:'invalid (unsupported) domain'.
+	^ self error:'invalid (unsupported) domain'.
     ].
     addrLen := domainClass socketAddressSize.
     addr := domainClass new.
@@ -2823,30 +2823,30 @@
     char dotted[20] ;
 
     if (!__isSmallInteger(addrLen)) {
-        DBGPRINTF(("SOCKET: bad addrLen\n"));
-        RETURN (false);
+	DBGPRINTF(("SOCKET: bad addrLen\n"));
+	RETURN (false);
     }
     alen0 = __intVal(addrLen);
     sock = SOCKET_FROM_FD(__intVal(serverSocketFd));
 
     if (blocking == false) {
 # if defined(O_NONBLOCK) && defined(SET_NDELAY)
-        flags = fcntl(sock, F_GETFL);
-        fcntl(sock, F_SETFL, flags | O_NONBLOCK);
+	flags = fcntl(sock, F_GETFL);
+	fcntl(sock, F_SETFL, flags | O_NONBLOCK);
 # endif
     }
 
 # ifdef DO_WRAP_CALLS
     do {
-        __threadErrno = 0;
-        alen = alen0;
-        newSock = STX_WSA_CALL3("accept", accept, sock, &sa, &alen);
+	__threadErrno = 0;
+	alen = alen0;
+	newSock = STX_WSA_CALL3("accept", accept, sock, &sa, &alen);
     } while ((newSock < 0) && (__threadErrno == EINTR));
 # else
     __BEGIN_INTERRUPTABLE__
     do {
-        alen = alen0;
-        newSock = accept(sock, (struct sockaddr *) &sa, &alen);
+	alen = alen0;
+	newSock = accept(sock, (struct sockaddr *) &sa, &alen);
     } while ((newSock < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
 # endif
@@ -2854,43 +2854,43 @@
 
     if (blocking == false) {
 # if defined(O_NDELAY) && defined(SET_NDELAY)
-        fcntl(sock, F_SETFL, flags);
+	fcntl(sock, F_SETFL, flags);
 # endif
     }
 
     if (newSock < 0) {
-        DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
-        __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        RETURN (false);
+	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
+	__INST(lastErrorNumber) = __MKSMALLINT(errno);
+	RETURN (false);
     }
 
     if (__isNonNilObject(addr)) {
-        OBJ oClass;
-        int nInstVars, nInstBytes, objSize;
-        char *cp;
-
-        oClass = __qClass(addr);
-        if (! __isBytes(addr) ) {
-            DBGPRINTF(("SOCKET: bad addr\n"));
-            closesocket(newSock);
-            RETURN (false);
-        }
-
-        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-        nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
-        objSize = __qSize(addr) - nInstBytes;
-        cp = (char *)__InstPtr(addr) + nInstBytes;
-        if (objSize < alen) {
-            DBGPRINTF(("SOCKET: bad addr\n"));
-            closesocket(newSock);
-            RETURN (false);
-        }
-
-        /*
-         * extract the partners address
-         */
-        bcopy((char *)&sa, cp, alen);
-        addrLen = __MKSMALLINT(alen);
+	OBJ oClass;
+	int nInstVars, nInstBytes, objSize;
+	char *cp;
+
+	oClass = __qClass(addr);
+	if (! __isBytes(addr) ) {
+	    DBGPRINTF(("SOCKET: bad addr\n"));
+	    closesocket(newSock);
+	    RETURN (false);
+	}
+
+	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+	nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
+	objSize = __qSize(addr) - nInstBytes;
+	cp = (char *)__InstPtr(addr) + nInstBytes;
+	if (objSize < alen) {
+	    DBGPRINTF(("SOCKET: bad addr\n"));
+	    closesocket(newSock);
+	    RETURN (false);
+	}
+
+	/*
+	 * extract the partners address
+	 */
+	bcopy((char *)&sa, cp, alen);
+	addrLen = __MKSMALLINT(alen);
     }
 
     /*
@@ -2898,43 +2898,43 @@
      */
 # ifdef WIN32
     {
-        int _fd = _open_osfhandle((long)newSock, 0);
-        fp = fdopen(_fd, "r+");
-        DBGPRINTF(("SOCKET: sock=%d fd=%d fp=%x\n",newSock,_fd, fp));
+	int _fd = _open_osfhandle((long)newSock, 0);
+	fp = fdopen(_fd, "r+");
+	DBGPRINTF(("SOCKET: sock=%d fd=%d fp=%x\n",newSock,_fd, fp));
     }
 # else
     fp = fdopen(newSock, "r+");
 # endif
 
     if (! fp) {
-        DBGPRINTF(("SOCKET: fdopen call failed\n"));
-        __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	DBGPRINTF(("SOCKET: fdopen call failed\n"));
+	__INST(lastErrorNumber) = __MKSMALLINT(errno);
 #  ifdef DO_WRAP_CALLS
-        {
-          int ret;
-          do {
-              __threadErrno = 0;
-              ret = STX_WSA_CALL1("closesocket", closesocket, newSock);
-          } while ((ret < 0) && (__threadErrno == EINTR));
-        }
+	{
+	  int ret;
+	  do {
+	      __threadErrno = 0;
+	      ret = STX_WSA_CALL1("closesocket", closesocket, newSock);
+	  } while ((ret < 0) && (__threadErrno == EINTR));
+	}
 #  else
-        closesocket(newSock);
+	closesocket(newSock);
 #  endif
-        DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", newSock));
-        RETURN (false);
+	DBGFPRINTF((stderr, "SOCKET: close (fdopen failed) (%d)\n", newSock));
+	RETURN (false);
     }
     __INST(handleType) = @symbol(socketFilePointer);
 
     if ((@global(FileOpenTrace) == true) || __debugging__) {
 # ifdef WIN32
-        {
-            HANDLE h;
-            int _fd = fileno(fp);
-            h = (HANDLE)_get_osfhandle(_fd);
-            console_fprintf(stderr, "fdopen [Socket] -> %x (fd: %d) (H: %x)\n", fp, _fd, h);
-        }
+	{
+	    HANDLE h;
+	    int _fd = fileno(fp);
+	    h = (HANDLE)_get_osfhandle(_fd);
+	    console_fprintf(stderr, "fdopen [Socket] -> %x (fd: %d) (H: %x)\n", fp, _fd, h);
+	}
 # else
-        console_fprintf(stderr, "fdopen [Socket] -> %x (fd: %d)\n", fp, newSock);
+	console_fprintf(stderr, "fdopen [Socket] -> %x (fd: %d)\n", fp, newSock);
 # endif
     }
 
@@ -2952,11 +2952,11 @@
     // object.
 # endif
     {
-        OBJ t;
-
-        t = __MKEXTERNALADDRESS(fp);
-        __INST(handle) = t;
-        __STORE(self, t);
+	OBJ t;
+
+	t = __MKEXTERNALADDRESS(fp);
+	__INST(handle) = t;
+	__STORE(self, t);
     }
 #endif /* not NO_SOCKET */
 %}.
@@ -2966,7 +2966,7 @@
     port := aSocket port.
 
     addr notNil ifTrue:[
-        peer := addr.
+	peer := addr.
     ].
 
     ^ true
@@ -3168,12 +3168,12 @@
 
 shutdown: howNum
     "shutDown the socket - inform it that no more I/O will be performed.
-         0 - read side   (no further reads)
-         1 - write side  (no further writes)
-         2 - both        (no further I/O at all)
+	 0 - read side   (no further reads)
+	 1 - write side  (no further writes)
+	 2 - both        (no further I/O at all)
      shutDown:2
-        discards any pending data
-        (as opposed to close, which might wait until data is delivered as set by LINGER)"
+	discards any pending data
+	(as opposed to close, which might wait until data is delivered as set by LINGER)"
 
 %{
 #ifndef NO_SOCKET
@@ -3182,21 +3182,21 @@
 
     fp = __INST(handle);
     if ((fp != nil) && __isSmallInteger(howNum)) {
-        SOCKET sock;
-        int ret;
-
-        sock = SOCKET_FROM_FILE_OBJECT(fp);
+	SOCKET sock;
+	int ret;
+
+	sock = SOCKET_FROM_FILE_OBJECT(fp);
 # ifdef DO_WRAP_CALLS
-        do {
-            __threadErrno = 0;
-            DBGFPRINTF((stderr, "SOCKET: shutDown...\n"));
-            ret = STX_WSA_NOINT_CALL2("shutdown", shutdown, sock, __intVal(howNum));
-            DBGFPRINTF((stderr, "SOCKET: shutDown -> %d (%d)\n", ret, __threadErrno));
-        } while ((ret < 0) && (__threadErrno == EINTR));
+	do {
+	    __threadErrno = 0;
+	    DBGFPRINTF((stderr, "SOCKET: shutDown...\n"));
+	    ret = STX_WSA_NOINT_CALL2("shutdown", shutdown, sock, __intVal(howNum));
+	    DBGFPRINTF((stderr, "SOCKET: shutDown -> %d (%d)\n", ret, __threadErrno));
+	} while ((ret < 0) && (__threadErrno == EINTR));
 # else
-        __BEGIN_INTERRUPTABLE__
-        shutdown(sock, __intVal(howNum));
-        __END_INTERRUPTABLE__
+	__BEGIN_INTERRUPTABLE__
+	shutdown(sock, __intVal(howNum));
+	__END_INTERRUPTABLE__
 # endif
     }
 #endif
@@ -3414,7 +3414,7 @@
     |domainName domainCode typeCode error|
 
     handle notNil ifTrue:[
-        ^ self errorAlreadyOpen
+	^ self errorAlreadyOpen
     ].
     domainName := SocketAddress domainCodeFromName:domainArg.
     domainCode := OperatingSystem domainCodeOf:domainName.
@@ -3428,19 +3428,19 @@
     SOCKET sock;
 
     if (! __isSmallInteger(domainCode)) {
-        error = @symbol(badArgument1);
-        goto out;
+	error = @symbol(badArgument1);
+	goto out;
     }
     if (! __isSmallInteger(typeCode)) {
-        error = @symbol(badArgument2);
-        goto out;
+	error = @symbol(badArgument2);
+	goto out;
     }
     if (protocolNumber != nil) {
-        if (!__isSmallInteger(protocolNumber)) {
-            error = @symbol(badArgument3);
-            goto out;
-        }
-        proto = __intVal(protocolNumber);
+	if (!__isSmallInteger(protocolNumber)) {
+	    error = @symbol(badArgument3);
+	    goto out;
+	}
+	proto = __intVal(protocolNumber);
     }
 
 
@@ -3453,20 +3453,20 @@
 # ifdef SOCKET_BLOCKS
 #  ifdef DO_WRAP_CALLS
     do {
-        __threadErrno = 0;
-        sock = STX_WSA_NOINT_CALL3("socket", socket, dom, typ, proto);
+	__threadErrno = 0;
+	sock = STX_WSA_NOINT_CALL3("socket", socket, dom, typ, proto);
     } while ((sock < 0) && (__threadErrno == EINTR));
 #  else
     __BEGIN_INTERRUPTABLE__
     do {
-        DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
-        sock = socket(dom, typ, proto);
+	DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
+	sock = socket(dom, typ, proto);
 #   if defined(EPROTONOSUPPORT) /* for SGI */
-        if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
-            DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
-            proto = 0;
-            sock = socket(dom, typ, 0);
-        }
+	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
+	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
+	    proto = 0;
+	    sock = socket(dom, typ, 0);
+	}
 #   endif
     } while ((sock < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
@@ -3475,9 +3475,9 @@
     sock = socket(dom, typ, proto);
 #  if defined(EPROTONOSUPPORT) /* for SGI */
     if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
-        DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
-        proto = 0;
-        sock = socket(dom, typ, 0);
+	DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
+	proto = 0;
+	sock = socket(dom, typ, 0);
     }
 #  endif
 # endif
@@ -3490,91 +3490,91 @@
     if (sock < 0)
 # endif
     {
-        DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
-        __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
+	__INST(lastErrorNumber) = __MKSMALLINT(errno);
     } else {
 # ifdef SO_REUSEADDR
-        if (reuse == true) {
-            DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
-            if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
-                DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
-            }
-        }
+	if (reuse == true) {
+	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
+	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
+		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
+	    }
+	}
 # endif /* SO_REUSEADDR */
 
 # ifdef SET_LINGER_WHEN_CREATING_SOCKET
 #  ifdef SO_LINGER
-        {
-            struct linger l;
-
-            l.l_onoff = 1;
-            l.l_linger = 30;
-            setsockopt( sock, SOL_SOCKET, SO_LINGER, &l, sizeof(l));
-        }
+	{
+	    struct linger l;
+
+	    l.l_onoff = 1;
+	    l.l_linger = 30;
+	    setsockopt( sock, SOL_SOCKET, SO_LINGER, &l, sizeof(l));
+	}
 #  endif
 # endif
 # ifdef WIN32
-        /*
-         * make it blocking
-         */
-        {
-            int zero = 0;
-
-            ioctlsocket(sock, FIONBIO, &zero);
-        }
+	/*
+	 * make it blocking
+	 */
+	{
+	    int zero = 0;
+
+	    ioctlsocket(sock, FIONBIO, &zero);
+	}
 # endif
-        /*
-         * make it a FILE *
-         */
+	/*
+	 * make it a FILE *
+	 */
 # ifdef WIN32
-        {
-            int _fd = _open_osfhandle((long)sock, 0);
-            fp = fdopen(_fd, "r+");
-            DBGPRINTF(("SOCKET: sock=%d fd=%d fp=%x\n",sock,_fd, fp));
-        }
+	{
+	    int _fd = _open_osfhandle((long)sock, 0);
+	    fp = fdopen(_fd, "r+");
+	    DBGPRINTF(("SOCKET: sock=%d fd=%d fp=%x\n",sock,_fd, fp));
+	}
 # else
-        fp = fdopen(sock, "r+");
+	fp = fdopen(sock, "r+");
 # endif
-        if (! fp) {
-            DBGPRINTF(("SOCKET: fdopen call failed\n"));
-            __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	if (! fp) {
+	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
+	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
 # ifdef DO_WRAP_CALLS
-            { int ret;
-
-              do {
-                __threadErrno = 0;
-                ret = STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
-              } while ((ret < 0) && (__threadErrno == EINTR));
-            }
+	    { int ret;
+
+	      do {
+		__threadErrno = 0;
+		ret = STX_WSA_NOINT_CALL1("closesocket", closesocket, sock);
+	      } while ((ret < 0) && (__threadErrno == EINTR));
+	    }
 # else
-            __BEGIN_INTERRUPTABLE__
-            closesocket(sock);
-            DBGFPRINTF((stderr, "SOCKET: fdopen failed (%d)\n", sock));
-            __END_INTERRUPTABLE__
+	    __BEGIN_INTERRUPTABLE__
+	    closesocket(sock);
+	    DBGFPRINTF((stderr, "SOCKET: fdopen failed (%d)\n", sock));
+	    __END_INTERRUPTABLE__
 # endif
-        } else {
-            __INST(handleType) = @symbol(socketFilePointer);
-
-            if ((@global(FileOpenTrace) == true) || __debugging__) {
-                console_fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
-            }
+	} else {
+	    __INST(handleType) = @symbol(socketFilePointer);
+
+	    if ((@global(FileOpenTrace) == true) || __debugging__) {
+		console_fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
+	    }
 
 # if 0
-            // The original code was:
-            __INST(handle) = __MKEXTERNALADDRESS(fp); __STORESELF(handle);
-            // but for that, gcc generates wrong code, which loads self (volatile) into
-            // a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp.
-            // That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old
-            // object.
+	    // The original code was:
+	    __INST(handle) = __MKEXTERNALADDRESS(fp); __STORESELF(handle);
+	    // but for that, gcc generates wrong code, which loads self (volatile) into
+	    // a register (bp), then calls __MKEXTERNALADDRESS, then stores indirect bp.
+	    // That is wrong if a scavenge occurs in __MKEXTERNALADDRESS, as bp is now still pointing to the old
+	    // object.
 # endif
-            {
-                OBJ t;
-
-                t = __MKEXTERNALADDRESS(fp);
-                __INST(handle) = t;
-                __STORE(self, t);
-            }
-        }
+	    {
+		OBJ t;
+
+		t = __MKEXTERNALADDRESS(fp);
+		__INST(handle) = t;
+		__STORE(self, t);
+	    }
+	}
     }
 #endif
 out:;
@@ -3582,14 +3582,14 @@
 
     "all ok?"
     handle notNil ifTrue:[
-        domain := domainArg.
-        socketType := typeArg.
-        Lobby register:self.
+	domain := domainArg.
+	socketType := typeArg.
+	Lobby register:self.
     ] ifFalse:[
-        error notNil ifTrue:[
-            ^ self primitiveFailed:error.
-        ].
-        ^ self openError
+	error notNil ifTrue:[
+	    ^ self primitiveFailed:error.
+	].
+	^ self openError
     ].
 
     "
@@ -3991,9 +3991,9 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.257 2010-07-05 16:47:15 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.258 2010-07-30 09:06:25 ca Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.257 2010-07-05 16:47:15 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.258 2010-07-30 09:06:25 ca Exp $'
 ! !