*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Wed, 11 Aug 1999 16:42:44 +0200
changeset 790 6f58d65fac5e
parent 789 3c8cac1a92f5
child 791 101799cd7ef0
*** empty log message ***
Socket.st
Socket_win32.st
--- a/Socket.st	Wed Aug 11 16:40:15 1999 +0200
+++ b/Socket.st	Wed Aug 11 16:42:44 1999 +0200
@@ -1817,7 +1817,9 @@
 	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
 	    case BYTEARRAY:
 	    case WORDARRAY:
+	    case SWORDARRAY:
 	    case LONGARRAY:
+	    case SLONGARRAY:
 	    case FLOATARRAY:
 	    case DOUBLEARRAY:
 		break;
@@ -2050,28 +2052,28 @@
 	    cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
 	    n = __byteArraySize(addrBytes);
 	    if (alen < n) n = alen;
-#ifdef DGRAM_DEBUG
+# ifdef DGRAM_DEBUG
 	    printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]);
-#endif
+# endif
 	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
-#ifdef AF_INET
+# ifdef AF_INET
 	    if (__INST(domain) == @symbol(inet)) {
 		sa.in.sin_family = AF_INET;
 		sa.in.sin_port = htons((u_short) __intVal(portNo)); 
 	    }
-#endif
-#ifdef AF_INET6
+# endif
+# ifdef AF_INET6
 	    if (__INST(domain) == @symbol(inet6)) {
 		sa.in6.sin6_family = AF_INET;
 		sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
 	    }
-#endif
-#ifdef AF_APPLETALK
+# endif
+# ifdef AF_APPLETALK
 	    if (__INST(domain) == @symbol(appletalk)) {
 		sa.at.sat_family = AF_INET;
 		sa.at.sat_port = __intVal(portNo);
 	    }
-#endif
+# endif
 	}
 
 	oClass = __Class(aDataBuffer);
@@ -2080,19 +2082,27 @@
 		offs = __intVal(startIndex) - 1;
 		break;
 	    case WORDARRAY:
-		offs = (__intVal(startIndex) - 1) * sizeof(short);
+	    case SWORDARRAY:
+		offs = (__intVal(startIndex) - 1) * 2;
 		break;
 	    case LONGARRAY:
-		offs = (__intVal(startIndex) - 1) * sizeof(long);
+	    case SLONGARRAY:
+		offs = (__intVal(startIndex) - 1) * 4;
 		break;
+	    case LONGLONGARRAY:
+	    case SLONGLONGARRAY:
+		offs = (__intVal(startIndex) - 1) * 8;
+# ifdef __NEED_LONGLONG_ALIGN
+		offs += 4;
+# endif
 	    case FLOATARRAY:
 		offs = (__intVal(startIndex) - 1) * sizeof(float);
 		break;
 	    case DOUBLEARRAY:
 		offs = (__intVal(startIndex) - 1) * sizeof(double);
-#ifdef NEED_DOUBLE_ALIGN
-		offs += sizeof(long);
-#endif
+# ifdef __NEED_DOUBLE_ALIGN
+		offs += 4;
+# endif
 		break;
 	    default:
 		goto bad;
@@ -2105,21 +2115,21 @@
 	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
 	cp += offs;
 	if ((offs + nBytes) > objSize) {
-#ifdef DGRAM_DEBUG
+# ifdef DGRAM_DEBUG
 	    printf("cut off ...\n");
-#endif
+# endif
 	    nBytes = objSize - offs;
 	}
 
 	norder = htonl(sa.in.sin_addr.s_addr);
-#ifdef DGRAM_DEBUG
+# ifdef DGRAM_DEBUG
 	printf("sending %d bytes ... to ", nBytes);
 	printf("%d.%d.%d.%d\n",
 		    (norder >> 24) & 0xFF,
 		    (norder >> 16) & 0xFF,
 		    (norder >> 8) & 0xFF,
 		    norder & 0xFF);
-#endif
+# endif
 
 	__BEGIN_INTERRUPTABLE__
 	do {
@@ -4183,5 +4193,5 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.123 1999-08-11 14:40:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.124 1999-08-11 14:42:43 cg Exp $'
 ! !
--- a/Socket_win32.st	Wed Aug 11 16:40:15 1999 +0200
+++ b/Socket_win32.st	Wed Aug 11 16:42:44 1999 +0200
@@ -1029,7 +1029,8 @@
      This is the reverse operation to #hostWithAppletalkAddress:."
 
 %{
-#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
+#if !defined(NO_SOCKET)
+# ifdef AF_APPLETALK
     struct sockaddr_at sa ;
     struct hostent *hp ;
     long addr;
@@ -1064,7 +1065,8 @@
 	__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sat_addr.s_node) & 0xFF;
        RETURN (rslt);
     }
-#endif
+# endif
+#endif /* !NO_SOCKET */
 %}.
     ^ nil
 
@@ -1085,7 +1087,8 @@
     b3 := anAddress at:3.
     b4 := anAddress at:4.
 %{
-#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
+#if !defined(NO_SOCKET)
+# ifdef AF_APPLETALK
     struct sockaddr_at sa ;
     struct hostent *hp ;
 
@@ -1118,9 +1121,11 @@
     if (hp != NULL) {
 	RETURN (__MKSTRING(hp->h_name));
     }
-#endif
-    RETURN (nil);
+# endif
+#endif /* !NO_SOCKET */
 %}.
+    ^ nil
+
     "
      Socket appletalkAddressOfHost:'clam'
      Socket hostWithAppletalkAddress:#[1 2 3]
@@ -1129,7 +1134,8 @@
 
 primHostWithIpAddress:b1 a1:b2 a2:b3 a3:b4
 %{
-#if !defined(NO_SOCKET) && defined(AF_INET)
+#if !defined(NO_SOCKET)
+# ifdef AF_INET
     struct sockaddr_in sa ;
     struct hostent *hp ;
 
@@ -1165,11 +1171,10 @@
      * return it in dot-notation
      */
     RETURN (__MKSTRING(inet_ntoa(sa.sin_addr)));
-#else
-    RETURN (nil);
-#endif
+# endif
+#endif /* !NO_SOCKET */
 %}.
-
+    ^ nil
 !
 
 hostWithIpAddress:anAddress
@@ -1205,7 +1210,8 @@
      This is the reverse operation to #hostWithIpAddress:."
 
 %{
-#if !defined(NO_SOCKET) && defined(AF_INET)
+#if !defined(NO_SOCKET)
+# ifdef AF_INET
     struct sockaddr_in sa ;
     struct hostent *hp ;
     long addr;
@@ -1246,7 +1252,8 @@
 	__ByteArrayInstPtr(rslt)->ba_element[3] = (sa.sin_addr.s_addr >> 0) & 0xFF;
        RETURN (rslt);
     }
-#endif
+# endif /* AF_INET */
+#endif /* !NO_SOCKET */
 %}.
     ^ nil
 
@@ -1313,7 +1320,7 @@
     if (htonl(0x76543210) == 0x76543210) {
 	RETURN (true);
     }
-#endif
+#endif /* !NO_SOCKET */
 %}.
     ^ false
 
@@ -1335,7 +1342,7 @@
     if (htons(0x3210) == 0x3210) {
 	RETURN (true);
     }
-#endif
+#endif /* !NO_SOCKET */
 %}.
     ^ false
 
@@ -1395,7 +1402,7 @@
 	}
 	RETURN ( nil );
     }
-#endif
+#endif /* !NO_SOCKET */
     RETURN ( nil );
 %}
     "
@@ -1435,7 +1442,7 @@
     if (servent) {
 	RETURN ( __MKSTRING(servent->s_proto) );
     }
-#endif
+#endif /* !NO_SOCKET */
     RETURN ( nil );
 %}
     "
@@ -1740,11 +1747,7 @@
     int flags = 0;
 
     if (fp != nil) {
-#ifdef WIN32
 	sock = _get_osfhandle(fileno(__FILEVal(fp)));
-#else
-	sock = fileno(__FILEVal(fp));
-#endif
 	oClass = __Class(aDataBuffer);
 	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
 	    case BYTEARRAY:
@@ -1771,7 +1774,7 @@
 	    }
 	}
 
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	do {
 	    if (addrBytes == nil) {
 		n = __doWrapCall6(1,(void*)recvfrom,(void *)sock, (void *)cp, (void *)objSize, (void *)flags, (void *)0, (void *)0);
@@ -1779,7 +1782,7 @@
 		n = __doWrapCall6(1,(void*)recvfrom,(void *)sock, (void *)cp, (void *)objSize, (void *)flags, (void *)&sa, (void *)&alen);
 	    }
 	} while ((n < 0) && (errno == EINTR));
-#else
+# else
 	__BEGIN_INTERRUPTABLE__
 	do {
 	    if (addrBytes == nil) {
@@ -1789,7 +1792,7 @@
 	    }
 	} while ((n < 0) && (errno == EINTR));
 	__END_INTERRUPTABLE__
-#endif
+# endif
 	if (n >= 0) {
 	    if (addrBytes != nil) {
 		oClass = __Class(addrBytes);
@@ -1821,7 +1824,9 @@
 		 * XXXX add addressing stuff for other domains here ...
 		 */
 # ifdef AF_INET6
-# endif /* AF_INET6 */
+		if (myDomain == @symbol(inet6)) {
+		}
+# endif
 
 # ifdef AF_X25
 		if (myDomain == @symbol(x25)) {
@@ -1884,7 +1889,7 @@
 	}
 	nReceived = __MKSMALLINT(n);
     }
-#endif
+#endif /* !NO_SOCKET */
 bad: ;
 %}.
     nReceived notNil ifTrue:[
@@ -1980,11 +1985,7 @@
     if ((fp != nil) 
      && __isSmallInteger(startIndex)
      && __isSmallInteger(count)) {
-#ifdef WIN32
 	sock = _get_osfhandle(fileno(__FILEVal(fp)));
-#else
-	sock = fileno(__FILEVal(fp));
-#endif
 
 	if (addrBytes == nil) {
 	    alen = 0;
@@ -1995,28 +1996,28 @@
 	    cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
 	    n = __byteArraySize(addrBytes);
 	    if (alen < n) n = alen;
-#ifdef DGRAM_DEBUG
+# ifdef DGRAM_DEBUG
 	    printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]);
-#endif
+# endif
 	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
-#ifdef AF_INET
+# ifdef AF_INET
 	    if (__INST(domain) == @symbol(inet)) {
 		sa.in.sin_family = AF_INET;
 		sa.in.sin_port = htons((u_short) __intVal(portNo)); 
 	    }
-#endif
-#ifdef AF_INET6
+# endif
+# ifdef AF_INET6
 	    if (__INST(domain) == @symbol(inet6)) {
 		sa.in6.sin6_family = AF_INET;
 		sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
 	    }
-#endif
-#ifdef AF_APPLETALK
+# endif
+# ifdef AF_APPLETALK
 	    if (__INST(domain) == @symbol(appletalk)) {
 		sa.at.sat_family = AF_INET;
 		sa.at.sat_port = __intVal(portNo);
 	    }
-#endif
+# endif
 	}
 
 	oClass = __Class(aDataBuffer);
@@ -2025,19 +2026,28 @@
 		offs = __intVal(startIndex) - 1;
 		break;
 	    case WORDARRAY:
-		offs = (__intVal(startIndex) - 1) * sizeof(short);
+	    case SWORDARRAY:
+		offs = (__intVal(startIndex) - 1) * 2;
 		break;
 	    case LONGARRAY:
-		offs = (__intVal(startIndex) - 1) * sizeof(long);
+	    case SLONGARRAY:
+		offs = (__intVal(startIndex) - 1) * 4;
+		break;
+	    case LONGLONGARRAY:
+	    case SLONGLONGARRAY:
+		offs = (__intVal(startIndex) - 1) * 8;
+# ifdef __NEED_LONGLONG_ALIGN
+		offs += 4;
+# endif
 		break;
 	    case FLOATARRAY:
 		offs = (__intVal(startIndex) - 1) * sizeof(float);
 		break;
 	    case DOUBLEARRAY:
 		offs = (__intVal(startIndex) - 1) * sizeof(double);
-#ifdef NEED_DOUBLE_ALIGN
-		offs += sizeof(long);
-#endif
+# ifdef __NEED_DOUBLE_ALIGN
+		offs += 4;
+# endif
 		break;
 	    default:
 		goto bad;
@@ -2050,39 +2060,39 @@
 	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
 	cp += offs;
 	if ((offs + nBytes) > objSize) {
-#ifdef DGRAM_DEBUG
+# ifdef DGRAM_DEBUG
 	    printf("cut off ...\n");
-#endif
+# endif
 	    nBytes = objSize - offs;
 	}
 
 	norder = htonl(sa.in.sin_addr.s_addr);
-#ifdef DGRAM_DEBUG
+# ifdef DGRAM_DEBUG
 	printf("sending %d bytes ... to ", nBytes);
 	printf("%d.%d.%d.%d\n",
 		    (norder >> 24) & 0xFF,
 		    (norder >> 16) & 0xFF,
 		    (norder >> 8) & 0xFF,
 		    norder & 0xFF);
-#endif
-
-#ifdef WRAP_STDIO
+# endif
+
+# ifdef WRAP_STDIO
 	do {
 	    n = __doWrapCall6(1,(void*)sendto,(void *)sock, (void *)cp, (void *)nBytes, (void *)_flags, (void *)saPtr, (void *)alen);
 	} while ((n < 0) && (errno == EINTR));
-#else
+# else
 	__BEGIN_INTERRUPTABLE__
 	do {
 	    n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
 	} while ((n < 0) && (errno == EINTR));
 	__END_INTERRUPTABLE__
-#endif
+# endif
 	if (n < 0) {
 	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
 	}
 	RETURN (__MKSMALLINT(n));
     }
-#endif
+#endif /* !NO_SOCKET */
 bad: ;
 %}.
     "
@@ -2515,11 +2525,7 @@
 	RETURN (false);
     }
 
-#ifdef WIN32
     sock = _get_osfhandle(fileno(__FILEVal(t)));
-#else
-    sock = fileno(__FILEVal(t));
-#endif
 
 # ifdef SO_REUSEADDR
     if (reuse == true) {
@@ -2529,17 +2535,17 @@
     }
 # endif /* SO_REUSEADDR */
 
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
     do {
 	ret = __doWrapCall3(1,(void*)bind,(void *)sock, (void *)&sa, (void *)sockaddr_size);
     } while ((ret < 0) && (errno == EINTR));
-#else
+# else
     __BEGIN_INTERRUPTABLE__
     do {
 	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
     } while ((ret < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
-#endif
+# endif
     if (ret < 0) {
 	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
 	__INST(lastErrorNumber) = __MKSMALLINT(errno);
@@ -2648,9 +2654,9 @@
     int flags;
     int sock, newSock;
     union {
-#ifdef AF_INET
+# ifdef AF_INET
 	struct sockaddr_in in;
-#endif
+# endif
 # ifdef AF_INET6
 	struct sockaddr_in6 in6;
 # endif
@@ -2664,34 +2670,32 @@
     int alen, alen0;
     struct hostent *he ;
     char dotted[20] ;
-
-#ifdef WIN32
+    struct sockaddr *saPtr = (struct sockaddr *)&sa;
+    int *alenPtr = &alen;
+
     sock = _get_osfhandle(_intVal(serverSocketFd));
-    flags = ioctlsocket(sock,FIONBIO , 0);
-#else
-    sock = _intVal(serverSocketFd);
-#endif
-
-#if defined(O_NDELAY) && defined(SET_NDELAY)
+    flags = ioctlsocket(sock, FIONBIO, 0);
+
+# if defined(O_NDELAY) && defined(SET_NDELAY)
     flags = ioctl(sock, F_GETFL, 0);
     ioctl(sock, F_SETFL, flags | O_NDELAY);
-#endif
-
-#ifdef AF_INET
+# endif
+
+# ifdef AF_INET
     if (__INST(domain) == @symbol(inet)) {
 	alen0 = sizeof(sa.in);
     }
-#endif
-#ifdef AF_INET6
+# endif
+# ifdef AF_INET6
     if (__INST(domain) == @symbol(inet6)) {
 	alen0 = sizeof(sa.in6);
     }
-#endif
-#ifdef AF_UNIX
+# endif
+# ifdef AF_UNIX
     if (__INST(domain) == @symbol(unix)) {
 	alen0 = sizeof(sa.un);
     }
-#endif
+# endif
 # ifdef AF_APPLETALK
     if (__INST(domain) == @symbol(appletalk)) {
 	alen0 = sizeof(sa.at);
@@ -2750,22 +2754,26 @@
     }
 # endif
 
-#ifdef WRAP_STDIO
+    /* testing ... */
+    saPtr = NULL;
+    alenPtr = NULL;
+
+# ifdef WRAP_STDIO
     do {
 	alen = alen0;
-	newSock = __doWrapCall3(1,(void*)accept,(void *)sock, (void *)&sa, (void *)&alen);
+	newSock = __doWrapCall3(1,(void*)accept,(void *)sock, (void *)saPtr, (void *)alenPtr);
     } while ((newSock < 0) && (errno == EINTR));
-#else
+# else
     __BEGIN_INTERRUPTABLE__
     do {
 	alen = alen0;
-	newSock = accept(sock, (struct sockaddr *) &sa, &alen);
+	newSock = accept(sock, (struct sockaddr *)saPtr, alenPtr);
     } while ((newSock < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
-#endif
-#if defined(O_NDELAY) && defined(SET_NDELAY)
+# endif
+# if defined(O_NDELAY) && defined(SET_NDELAY)
     ioctl(sock, F_SETFL, flags);
-#endif
+# endif
 
     if (newSock < 0) {
 	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
@@ -2776,7 +2784,7 @@
     /*
      * extract the partners address
      */
-#ifdef AF_INET
+# ifdef AF_INET
     if (__INST(domain) == @symbol(inet)) {
 	GETHOSTBYADDR(he, (char *) &sa.in.sin_addr.s_addr, alen, AF_INET);
 	if (! he) {
@@ -2793,9 +2801,9 @@
 	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
 	__STORESELF(peerName);
     }
-#endif
-
-#ifdef AF_INET6
+# endif
+
+# ifdef AF_INET6
     if (__INST(domain) == @symbol(inet6)) {
 	GETHOSTBYADDR(he, (char *) &sa.in6.sin6_addr.s6_addr, alen, AF_INET6);
 	if (! he) {
@@ -2817,16 +2825,16 @@
 	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
 	__STORESELF(peerName);
     }
-#endif
-
-#ifdef AF_UNIX
+# endif
+
+# ifdef AF_UNIX
     if (__INST(domain) == @symbol(unix)) {
 	DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
 	/* nothing to be done here */
     }
-#endif
-
-#ifdef AF_APPLETALK
+# endif
+
+# ifdef AF_APPLETALK
     if (__INST(domain) == @symbol(appletalk)) {
 	GETHOSTBYADDR(he, (char *) &sa.at.sat_addr, alen, AF_APPLETALK);
 	if (! he) {
@@ -2901,7 +2909,6 @@
     /* 
      * make it a FILE * 
      */
-#ifdef WIN32
     {
       HANDLE h;
       int _fd = _open_osfhandle(newSock, 0);
@@ -2909,34 +2916,32 @@
       h = (HANDLE)_get_osfhandle(_fd);
       DBGPRINTF(("nS:%x -> %x h:%x\n",newSock,_fd,h));
     }
-#else
-    fp = fdopen(newSock, "r+");
-#endif
+
     if (! fp) {
 	DBGPRINTF(("SOCKET: fdopen call failed\n"));
 	__INST(lastErrorNumber) = __MKSMALLINT(errno);
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	{ int ret;
 	  //int closesocket();
 	  do {
 	    ret = __doWrapCall1(0,(void*)closesocket,(void *)newSock);
 	  } while ((ret < 0) && (errno == EINTR));
 	}
-#else
+# else
 	__BEGIN_INTERRUPTABLE__
 	close(newSock);
 	__END_INTERRUPTABLE__
-#endif
+# endif
 	RETURN (false);
     } else {
-#ifdef BUGGY_STDIO_LIB
+# ifdef BUGGY_STDIO_LIB
 	setbuf(fp, NULL);
 	__INST(buffered) = false;
-#endif
+# endif
 	__INST(filePointer) = __MKOBJ(fp);
 	__STORESELF(filePointer);
     }
-#endif
+#endif /* !NO_SOCKET */
 %}.
     mode := #readwrite.
     Lobby register:self.
@@ -2959,15 +2964,11 @@
 
 	fp = __FILEVal(t);
 	fflush(fp);
-#ifdef WIN32
 	shutdown(_get_osfhandle(fileno(fp)),4);
-#else
-	shutdown(fileno(fp), 2);
-#endif
 	fclose(fp);
 	__INST(filePointer) = nil;
     }
-#endif
+#endif /* !NO_SOCKET */
 %}
 !
 
@@ -3036,7 +3037,7 @@
     myDomain = __INST(domain);
     bzero((char *) &sa, sizeof(sa)) ;
 
-#ifdef AF_INET
+# ifdef AF_INET
     if (myDomain == @symbol(inet)) {
 	/*
 	 * INET addressing: port must be a smallInteger;
@@ -3089,9 +3090,9 @@
 	sockaddr_size = sizeof(struct sockaddr_in);
 	ok = 1;
     }
-#endif /* AF_INET */
-
-#ifdef AF_INET6
+# endif /* AF_INET */
+
+# ifdef AF_INET6
     if (myDomain == @symbol(inet6)) {
 	/*
 	 * INET6 addressing: port must be a smallInteger;
@@ -3144,9 +3145,9 @@
 	sockaddr_size = sizeof(struct sockaddr_in6);
 	ok = 1;
     }
-#endif /* AF_INET6 */
-
-#ifdef AF_UNIX
+# endif /* AF_INET6 */
+
+# ifdef AF_UNIX
     if (myDomain == @symbol(unix)) {
 	char *pathName;
 	int l;
@@ -3171,9 +3172,9 @@
 	sockaddr_size = l + sizeof ( sa.un.sun_family );
 	ok = 1;
     }
-#endif /* AF_UNIX */
-
-#ifdef AF_APPLETALK
+# endif /* AF_UNIX */
+
+# ifdef AF_APPLETALK
     if (myDomain == @symbol(appletalk)) {
 	/*
 	 * APPLETALK addressing: port must be a smallInteger;
@@ -3224,35 +3225,35 @@
 	sockaddr_size = sizeof(struct sockaddr_at);
 	ok = 1;
     }
-#endif /* APPLETALK */
+# endif /* APPLETALK */
 
     /*
      * XXXX add addressing stuff for other domains here ...
      */
-#ifdef AF_X25
+# ifdef AF_X25
     if (myDomain == @symbol(x25)) {
     }
-#endif
-#ifdef AF_NS
+# endif
+# ifdef AF_NS
     if (myDomain == @symbol(ns)) {
     }
-#endif
+# endif
 # ifdef AF_DECnet
     if (myDomain == @symbol(decnet)) {
     }
 # endif
-#ifdef AF_NS 
+# ifdef AF_NS 
     if (myDomain == @symbol(xns)) {
     }
-#endif
-#ifdef AF_SNA
+# endif
+# ifdef AF_SNA
     if (myDomain == @symbol(sna)) {
     }
-#endif
-#ifdef AF_RAW 
+# endif
+# ifdef AF_RAW 
     if (myDomain == @symbol(raw)) {
     }
-#endif
+# endif
 # ifdef AF_ISO
     if (myDomain == @symbol(iso)) {
     }
@@ -3283,13 +3284,9 @@
 	RETURN (false);
     }
 
-#ifdef WIN32
     sock = _get_osfhandle(fileno(__FILEVal(t)));
-#else
-    sock = fileno(__FILEVal(t));
-#endif
-
-#if defined(O_NONBLOCK)
+
+# if defined(O_NONBLOCK)
     if (blocking != true) {
 	/*
 	 * set to non-blocking and wait later
@@ -3298,36 +3295,36 @@
 	/* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */
 	fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK);
     }
-#endif
+# endif
 
     /* 
      * connect 
      */
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
     do {
 	ret = __doWrapCall3(1,(void*)connect,(void *)sock, (void *)&sa, (void *)sockaddr_size);
     } while ((ret < 0) && (errno == EINTR));
-#else
+# else
     __BEGIN_INTERRUPTABLE__
     do {
 	ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size);
     } while ((ret < 0) 
 	     && ((errno == EINTR)
-#ifdef EAGAIN
+#  ifdef EAGAIN
 		 || (errno == EAGAIN)
-#endif
+#  endif
 		));
     __END_INTERRUPTABLE__
-#endif
+# endif
     if (ret < 0) { 
-#if defined(EINPROGRESS) || defined(EALREADY)
+# if defined(EINPROGRESS) || defined(EALREADY)
 	if (0
-# ifdef EINPROGRESS
+#  ifdef EINPROGRESS
 	    || (errno == EINPROGRESS) 
-# endif
-# ifdef EALREADY
+#  endif
+#  ifdef EALREADY
 	    || (errno == EALREADY)
-# endif
+#  endif
 	) {
 	    /*
 	     * We were interrupted. Do not call connect again
@@ -3337,10 +3334,10 @@
 
 	    isAsync = true;
 	} else
-#endif /* EINPROGRESS or EALREADY */
+# endif /* EINPROGRESS or EALREADY */
 	{
 	    DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno));
-#ifdef DUMP_ADDRESS
+# ifdef DUMP_ADDRESS
 	    {
 		char *cp = (char *)(&sa);
 		int i;
@@ -3350,17 +3347,17 @@
 		    printf(" %02x\n", *cp++);
 		}
 	    }
-#endif
+# endif
 	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
 	    RETURN (false);
 	}
     }
 
-#if defined(O_NONBLOCK)
+# if defined(O_NONBLOCK)
     if (blocking != true) {
 	fcntl(sock, F_SETFL, oldFlags);
     }
-#endif
+# endif
 
 #else /* NO_SOCKET */
     RETURN (false);
@@ -3439,31 +3436,27 @@
 	RETURN (false);
     }
 
-#ifdef WIN32
     sock = _get_osfhandle(fileno(__FILEVal(fp)));
-#else
-    sock = fileno(__FILEVal(fp));
-#endif
-
-#ifdef WRAP_STDIO
+
+# ifdef WRAP_STDIO
     do {
-	ret = __doWrapCall2(1,(void*)listen,(void *)sock, (void *)_intVal(aNumber));
+	ret = __doWrapCall2(1, (void*)listen, (void *)sock, (void *)_intVal(aNumber));
     } while ((ret < 0) && (errno == EINTR));
-#else
+# else
     __BEGIN_INTERRUPTABLE__
     do {
 	ret = listen(sock, _intVal(aNumber));
     } while ((ret < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
-#endif
+# endif
     if (ret < 0) {
 	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
 	__INST(lastErrorNumber) = __MKSMALLINT(errno);
 	RETURN (false);
     }
-#else
+#else /* NO_SOCKET */
     RETURN (false);
-#endif
+#endif /* NO_SOCKET */
 %}.
     ^ true
 !
@@ -3485,7 +3478,7 @@
 
 	__INST(filePointer) = nil;
 	fd = fileno(__FILEVal(fp));
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	{ int ret;
 	  //int closesocket();
 	  do {
@@ -3495,18 +3488,14 @@
 	    ret = __doWrapCall1(0,(void*)closesocket,(void *)_get_osfhandle(fd));
 	  } while ((ret < 0) && (errno == EINTR));
 	}
-#else
+# else
 	__BEGIN_INTERRUPTABLE__
-#ifdef WIN32
 	shutdown(_get_osfhandle(fd), 4);
-#else
-	shutdown(fd, 2);
-#endif
 	close(fd);
 	__END_INTERRUPTABLE__
-#endif
+# endif
     }
-#endif
+#endif /* !NO_SOCKET */
 %}
 ! !
 
@@ -3631,56 +3620,56 @@
 	}
 	proto = __intVal(protocolNumber);
     }
-	
+        
 
     /*
      * get address and protocol-family
      */
-#ifdef AF_UNIX
+# ifdef AF_UNIX
     if (domainArg == @symbol(unix)) {
 	dom = AF_UNIX;
     } else
-#endif
-#ifdef AF_INET
+# endif
+# ifdef AF_INET
     if (domainArg == @symbol(inet)) {
 	dom = AF_INET;
     } else
-#endif
-#ifdef AF_INET6
+# endif
+# ifdef AF_INET6
     if (domainArg == @symbol(inet6)) {
 	dom = AF_INET6;
     } else
-#endif
-#ifdef AF_DECnet
+# endif
+# ifdef AF_DECnet
     if (domainArg == @symbol(DECnet)) {
 	dom = AF_DECnet;
     } else
-#endif
-#ifdef AF_APPLETALK
+# endif
+# ifdef AF_APPLETALK
     if (domainArg == @symbol(appletalk)) {
 	dom = AF_APPLETALK;
     } else
-#endif
-#ifdef AF_X25
+# endif
+# ifdef AF_X25
     if (domainArg == @symbol(x25)) {
 	dom = AF_X25;
     } else
-#endif
-#ifdef AF_NS
+# endif
+# ifdef AF_NS
     if (domainArg == @symbol(xns)) {
 	dom = AF_NS;
     } else
-#endif
-#ifdef AF_SNA
+# endif
+# ifdef AF_SNA
     if (domainArg == @symbol(sna)) {
 	dom = AF_SNA;
     } else
-#endif
-#ifdef AF_RAW
+# endif
+# ifdef AF_RAW
     if (domainArg == @symbol(raw)) {
 	dom = AF_RAW;
     } else
-#endif
+# endif
 # ifdef AF_ISO
     if (domainArg == @symbol(iso)) {
 	dom = AF_ISO;
@@ -3716,50 +3705,50 @@
 	RETURN ( nil );
     }
 
-#ifdef SOCK_STREAM
+# ifdef SOCK_STREAM
     if (typeArg == @symbol(stream)) {
 	typ = SOCK_STREAM;
     } else
-#endif
-#ifdef SOCK_DGRAM
+# endif
+# ifdef SOCK_DGRAM
     if (typeArg == @symbol(datagram)) {
 	typ = SOCK_DGRAM;
     } else 
-#endif
-#ifdef SOCK_RAW
+# endif
+# ifdef SOCK_RAW
     if (typeArg == @symbol(raw))
 	typ = SOCK_RAW;
     else
-#endif
-#ifdef SOCK_SEQPACKET
+# endif
+# ifdef SOCK_SEQPACKET
     if (typeArg == @symbol(seqPacket))
 	typ = SOCK_SEQPACKET;
     else
-#endif
+# endif
     {
 	DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg)));
 	RETURN ( nil );
     }
 
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
     do {
 	sock = __doWrapCall3(1,(void*)socket,(void *)dom, (void *)typ, (void *)proto);
     } while ((sock < 0) && (errno == EINTR));
-#else
+# else
     __BEGIN_INTERRUPTABLE__
     do {
 	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 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);
 	}
-#endif
+#  endif
     } while ((sock < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
-#endif
+# endif
     if (sock < 0) {
 	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
 	__INST(lastErrorNumber) = __MKSMALLINT(errno);
@@ -3775,36 +3764,32 @@
 	/* 
 	 * make it a FILE * 
 	 */
-#ifdef WIN32
 	{
 	  int _fd = _open_osfhandle(sock, 0);
 	  fp = fdopen(_fd, "r+");
 	  DBGPRINTF(("nS1:%x -> %x\n",sock,_fd));
 	}
-#else
-	fp = fdopen(sock, "r+");
-#endif
 	if (! fp) {
 	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
 	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	    { int ret;
 	      //int closesocket();
 	      do {
 		ret = __doWrapCall1(0,(void*)closesocket,(void *)sock);
 	      } while ((ret < 0) && (errno == EINTR));
 	    }
-#else
+# else
 	    __BEGIN_INTERRUPTABLE__
 	    close(sock);
 	    __END_INTERRUPTABLE__
-#endif
+# endif
 	} else {
 	    __INST(filePointer) = __MKOBJ(fp);
 	    __STORESELF(filePointer);
 	}
     }
-#endif
+#endif /* !NO_SOCKET */
 %}.
 
     "all ok?"
@@ -3877,17 +3862,17 @@
     /*
      * create the socket
      */
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
     do {
 	sock = __doWrapCall3(1,(void*)socket,(void *)sa.sin_family, (void *)SOCK_STREAM,(void *)0);
     } while ((sock < 0) && (errno == EINTR));
-#else
+# else
     __BEGIN_INTERRUPTABLE__
     do {
 	sock = socket(sa.sin_family, SOCK_STREAM, 0);
     } while ((sock < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
-#endif
+# endif
     if (sock < 0) {
 	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_STREAM, errno));
 	__INST(lastErrorNumber) = __MKSMALLINT(errno);
@@ -3897,101 +3882,97 @@
 	 */
 	sa.sin_port = htons((u_short) _intVal(portNr)) ;
 
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	if (hostName != nil) {
 	    do {
 		ret = __doWrapCall3(1,(void*)connect,(void *)sock, (void *)&sa,(void *)sizeof(sa));
 	    } while ((ret < 0) && (errno == EINTR));
 	} else {
-#ifdef SO_REUSEADDR
+#  ifdef SO_REUSEADDR
 	    /*
 	     * should I also do this for DGRAM sockets ?
 	     */
 	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
 		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
 	    }
-#endif /* SO_REUSEADDR */
+#  endif /* SO_REUSEADDR */
 	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
 	    do {
 		ret = __doWrapCall3(1,(void*)bind,(void *)sock, (void *)&sa,(void *)sizeof(sa));
 	    } while ((ret < 0) && (errno == EINTR));
 	}
-#else
+# else
 	__BEGIN_INTERRUPTABLE__
 	if (hostName != nil) {
 	    do {
 		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
 	    } while ((ret < 0) && (errno == EINTR));
 	} else {
-#ifdef SO_REUSEADDR
+#  ifdef SO_REUSEADDR
 	    /*
 	     * should I also do this for DGRAM sockets ?
 	     */
 	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
 		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
 	    }
-#endif /* SO_REUSEADDR */
+#  endif /* SO_REUSEADDR */
 	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
 	    do {
 		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
 	    } while ((ret < 0) && (errno == EINTR));
 	}
 	__END_INTERRUPTABLE__
-#endif
+# endif
 	if (ret < 0) { 
 	    DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno));
 	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	    { int ret;
 	      //int closesocket();
 	      do {
 		ret = __doWrapCall1(0,(void*)closesocket,(void *)sock);
 	      } while ((ret < 0) && (errno == EINTR));
 	    }
-#else
+# else
 	    __BEGIN_INTERRUPTABLE__
 	    close(sock) ;
 	    __END_INTERRUPTABLE__
-#endif
+# endif
 	} else {
 	    /* 
 	     * make it a FILE * 
 	     */
-#ifdef WIN32
 	    {
 	      int _fd = _open_osfhandle(sock, 0);
 	      fp = fdopen(_fd, "r+");
 	      DBGPRINTF(("nS2:%x -> %x\n",sock,_fd));
 	    }
-#else
-	    fp = fdopen(sock, "r+");
-#endif
 	    if (! fp) {
 		DBGPRINTF(("SOCKET: fdopen failed\n"));
 		__INST(lastErrorNumber) = __MKSMALLINT(errno);
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 		{ int ret;
 		  //int closesocket();
 		  do {
 		    ret = __doWrapCall1(0,(void*)closesocket,(void *)sock);
 		  } while ((ret < 0) && (errno == EINTR));
 		}
-#else
+# else
 		__BEGIN_INTERRUPTABLE__
 		close(sock);
 		__END_INTERRUPTABLE__
-#endif
+# endif
 	    } else {
-#ifdef BUGGY_STDIO_LIB
+# ifdef BUGGY_STDIO_LIB
 		setbuf(fp, NULL);
 		__INST(buffered) = false;
-#endif
+# endif
 		__INST(filePointer) = __MKOBJ(fp);
 		__STORESELF(filePointer);
 	    }
 	}
     }
-#endif
+#endif /* !NO_SOCKET */
 %}.
     filePointer isNil ifTrue:[
 	^ nil
@@ -4067,17 +4048,17 @@
     /*
      * create the socket
      */
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
     do {
 	sock = __doWrapCall3(1,(void*)socket,(void *)sa.sin_family, (void *)SOCK_DGRAM, (void *)0);
     } while ((sock < 0) && (errno == EINTR));
-#else
+# else
     __BEGIN_INTERRUPTABLE__
     do {
 	sock = socket(sa.sin_family, SOCK_DGRAM, 0);
     } while ((sock < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
-#endif
+# endif
     if (sock < 0) {
 	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_DGRAM, errno));
 	__INST(lastErrorNumber) = __MKSMALLINT(errno);
@@ -4086,7 +4067,7 @@
 	 * ok,
 	 * connect/bind 
 	 */
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	if (hostName == nil) {
 	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
 	    do {
@@ -4097,7 +4078,7 @@
 		ret = __doWrapCall3(1,(void*)connect,(void *)sock, (void *)&sa,(void *)sizeof(sa));
 	    } while ((ret < 0) && (errno == EINTR));
 	}
-#else
+# else
 	__BEGIN_INTERRUPTABLE__
 	if (hostName == nil) {
 	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
@@ -4111,61 +4092,57 @@
 	    } while ((ret < 0) && (errno == EINTR));
 	}
 	__END_INTERRUPTABLE__
-#endif
+# endif
 	if (ret < 0) {
 	    DBGPRINTF(("SOCKET: bind/connect call failed\n"));
 	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 	    { int ret;
 	      //int closesocket();
 	      do {
 		ret = __doWrapCall1(0,(void*)closesocket,(void *)sock);
 	      } while ((ret < 0) && (errno == EINTR));
 	    }
-#else
+# else
 	    __BEGIN_INTERRUPTABLE__
 	    close(sock);
 	    __END_INTERRUPTABLE__
-#endif
+# endif
 	} else {
 	    /* 
 	     * make it a FILE * 
 	     */
-#ifdef WIN32
 	    {
 	      int _fd = _open_osfhandle(sock, 0);
 	      fp = fdopen(_fd, "r+");
 	      DBGPRINTF(("nS3:%x -> %x\n",sock,_fd));
 	    }
-#else
-	    fp = fdopen(sock, "r+");
-#endif
 	    if (! fp) {
 		DBGPRINTF(("SOCKET: fdopen call failed\n"));
 		__INST(lastErrorNumber) = __MKSMALLINT(errno);
-#ifdef WRAP_STDIO
+# ifdef WRAP_STDIO
 		{ int ret;
 		  //int closesocket();
 		  do {
 		    ret = __doWrapCall1(0,(void*)closesocket,(void *)sock);
 		  } while ((ret < 0) && (errno == EINTR));
 		}
-#else
+# else
 		__BEGIN_INTERRUPTABLE__
 		close(sock);
 		__END_INTERRUPTABLE__
-#endif
+# endif
 	    } else {
-#ifdef BUGGY_STDIO_LIB
+# ifdef BUGGY_STDIO_LIB
 		setbuf(fp, NULL);
 		__INST(buffered) = false;
-#endif
+# endif
 		__INST(filePointer) = __MKOBJ(fp);
 		__STORESELF(filePointer);
 	    }
 	}
     }
-#endif
+#endif /* !NO_SOCKET */
 %}.
     filePointer isNil ifTrue:[
 	^ nil
@@ -4205,11 +4182,7 @@
 	int sock;
 	int opt;
 
-#ifdef WIN32
 	sock = _get_osfhandle(fileno(__FILEVal(fp)));
-#else
-	sock = fileno(__FILEVal(fp));
-#endif
 	opt = _intVal(millis) / (1000 / HZ);
 	setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int));
 	RETURN(true);
@@ -4237,11 +4210,7 @@
 	int sock;
 	int opt;
 
-#ifdef WIN32
 	sock = _get_osfhandle(fileno(__FILEVal(fp)));
-#else
-	sock = fileno(__FILEVal(fp));
-#endif
 	opt = _intVal(millis) / (1000 / HZ);
 	setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int));
 	RETURN(true);
@@ -4254,6 +4223,6 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/Socket_win32.st,v 1.5 1999-06-18 12:52:49 ps Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/Socket_win32.st,v 1.6 1999-08-11 14:42:44 cg Exp $'
 ! !