Socket.st
changeset 1781 7e5b6c83e627
parent 1600 f3acd5382fa1
child 1839 c10cd58ec334
--- a/Socket.st	Mon Nov 13 18:19:57 2006 +0100
+++ b/Socket.st	Tue Nov 14 18:34:28 2006 +0100
@@ -9,7 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
 "{ Package: 'stx:libbasic2' }"
 
 NonPositionableExternalStream subclass:#Socket
@@ -3126,31 +3125,31 @@
     |isAsync err domainClass addr addrName|
 
     filePointer isNil ifTrue:[
-	^ self errorNotOpen
+        ^ self errorNotOpen
     ].
 
     domainClass := self class socketAddressClassForDomain:domain.
     domainClass isNil ifTrue:[
-	^ self error:'invalid (unsupported) domain'.
+        ^ self error:'invalid (unsupported) domain'.
     ].
 
     "/ backward compatibility: support for byteArray and string arg
 
     hostOrPathNameOrSocketAddr isString ifTrue:[
-	addr := domainClass hostName:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
-	addrName := hostOrPathNameOrSocketAddr.
+        addr := domainClass hostName:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
+        addrName := hostOrPathNameOrSocketAddr.
     ] ifFalse:[
-	hostOrPathNameOrSocketAddr isByteArray ifFalse:[
-	    ^ self error:'bad host (socketAddress) argument'
-	].
-	(hostOrPathNameOrSocketAddr isKindOf:SocketAddress) ifTrue:[
-	    addr := hostOrPathNameOrSocketAddr.
-	    portNrOrNameOrNil notNil ifTrue:[
-		addr port:portNrOrNameOrNil.
-	    ].
-	] ifFalse:[
-	    addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
-	].
+        hostOrPathNameOrSocketAddr isByteCollection ifFalse:[
+            ^ self error:'bad host (socketAddress) argument'
+        ].
+        (hostOrPathNameOrSocketAddr isKindOf:SocketAddress) ifTrue:[
+            addr := hostOrPathNameOrSocketAddr.
+            portNrOrNameOrNil notNil ifTrue:[
+                addr port:portNrOrNameOrNil.
+            ].
+        ] ifFalse:[
+            addr := domainClass hostAddress:hostOrPathNameOrSocketAddr port:portNrOrNameOrNil.
+        ].
     ].
 
 %{  /* STACK: 100000 */
@@ -3165,24 +3164,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)) {
-	    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)) {
+            fprintf(stderr, "Socket: bad socketAddr\n");
+            RETURN (false);
+        }
+        bcopy((__byteArrayVal(addr) + sockAddrOffs), &sa, sockaddr_size);
     }
 
     sock = SOCKET_FROM_FILE_OBJECT(fp);
@@ -3203,59 +3202,59 @@
      */
 # ifdef DO_WRAP_CALLS
     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)\n", 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)\n", ret, __threadErrno));
     } while ((ret < 0) && (__threadErrno == EINTR));
 # 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;
-
-		printf("address data:\n");
-		for (i=0; i<sockaddr_size; i++) {
-		    printf(" %02x\n", *cp++);
-		}
-	    }
+            {
+                char *cp = (char *)(&sa);
+                int i;
+
+                printf("address data:\n");
+                for (i=0; i<sockaddr_size; i++) {
+                    printf(" %02x\n", *cp++);
+                }
+            }
 # endif
-	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
-	    RETURN (false);
-	}
+            __INST(lastErrorNumber) = __MKSMALLINT(errno);
+            RETURN (false);
+        }
     }
 
 # if defined(O_NONBLOCK)
@@ -3269,16 +3268,16 @@
 # endif /* NO_SOCKET */
 %}.
     isAsync == true ifTrue:[
-	(self writeWaitWithTimeoutMs:timeout) ifTrue:[
-	    "/ a timeout occured
-	    "/ should cancel the connect?
-	    ^ false.
-	].
-	err := self getSocketError.
-	err ~~ 0 ifTrue:[
-	    lastErrorNumber := err.
-	    ^ false.
-	].
+        (self writeWaitWithTimeoutMs:timeout) ifTrue:[
+            "/ a timeout occured
+            "/ should cancel the connect?
+            ^ false.
+        ].
+        err := self getSocketError.
+        err ~~ 0 ifTrue:[
+            lastErrorNumber := err.
+            ^ false.
+        ].
     ].
     port := portNrOrNameOrNil.
     peer := addr.
@@ -4084,5 +4083,5 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.225 2006-02-15 13:52:13 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.226 2006-11-14 17:34:28 stefan Exp $'
 ! !