--- a/Socket.st Fri Oct 26 11:52:32 2012 +0200
+++ b/Socket.st Fri Oct 26 11:53:46 2012 +0200
@@ -20,7 +20,6 @@
!
!Socket primitiveDefinitions!
-
%{
/* #define DGRAM_DEBUG /* */
@@ -3507,7 +3506,7 @@
|domainName domainCode typeCode error|
handle notNil ifTrue:[
- ^ self errorAlreadyOpen
+ ^ self errorAlreadyOpen
].
domainName := SocketAddress domainCodeFromName:domainArg.
domainCode := OperatingSystem domainCodeOf:domainName.
@@ -3521,19 +3520,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);
}
@@ -3546,20 +3545,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__
@@ -3568,9 +3567,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
@@ -3583,98 +3582,98 @@
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;
- __stxWrapApiEnterCritical();
+ {
+ int _fd;
+ __stxWrapApiEnterCritical();
# ifdef __BORLANDC__
- _fd = _open_osfhandle((long)sock, 0);
+ _fd = _open_osfhandle((long)sock, 0);
# else
- _fd = (int)sock;
+ _fd = (int)sock;
# endif
- fp = fdopen(_fd, "r+");
- __stxWrapApiLeaveCritical();
- DBGPRINTF(("SOCKET: sock=%d fd=%d fp=%x\n",sock,_fd, fp));
- }
+ fp = fdopen(_fd, "r+");
+ __stxWrapApiLeaveCritical();
+ 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:;
@@ -3682,14 +3681,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:lastErrorNumber.
].
"
@@ -4053,9 +4052,9 @@
!Socket class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.272 2012-10-09 11:29:13 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.273 2012-10-26 09:53:46 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.272 2012-10-09 11:29:13 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.273 2012-10-26 09:53:46 stefan Exp $'
! !