Socket.st
changeset 4626 5e6419fb6699
parent 4587 caa262d036d2
child 4630 185f2775c1ca
--- a/Socket.st	Wed Mar 21 11:37:37 2018 +0100
+++ b/Socket.st	Wed Mar 21 19:35:48 2018 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1992 by Claus Gittinger
 	      All Rights Reserved
@@ -2412,9 +2410,7 @@
 
 receiveBuffer:aDataBuffer start:startIndex for:nBytes
     "receive data
-     Return the number of bytes received, or a negative number on error.
-     On error, the unix error code is left in the lastErrorNumber
-     instance variable.
+     Return the number of bytes received.
      The thread blocks until data arrives - you may want to wait before
      receiving, using #readWait or #readWaitWithTimeout:."
 
@@ -2425,99 +2421,106 @@
     OBJ fp = __INST(handle);
 
     if (fp != nil) {
-	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);
-	    }
-	}
+        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 = (INT)STX_WSA_NOINT_CALL4("recv", recv, sock, buffer, objSize, flags);
-	} while ((n < 0) && (__threadErrno == EINTR));
-	if (n < 0) {
-	    errno = __threadErrno;
-	}
-
-	if (allocatedBuffer) {
-	    if (n > 0) {
-		memcpy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, n);
-	    }
-	    free(allocatedBuffer);
-	}
+        if (extPtr) {
+            buffer = extPtr + offs;
+        } else {
+            allocatedBuffer = buffer = (char *)malloc(objSize);
+        }
+
+        do {
+            __threadErrno = 0;
+            n = (INT)STX_WSA_NOINT_CALL4("recv", recv, sock, buffer, objSize, flags);
+        } while ((n < 0) && (__threadErrno == EINTR));
+        if (n < 0) {
+            errno = __threadErrno;
+        }
+
+        if (allocatedBuffer) {
+            if (n > 0) {
+                memcpy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, 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) {
-	    error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
-	} else {
-	    RETURN(__MKSMALLINT(n));
-	}
+        if (n < 0) {
+            error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
+        } else {
+            RETURN(__MKSMALLINT(n));
+        }
     }
 #endif
 bad: ;
 %}.
     error notNil ifTrue:[
-	^ self readError:error.
+        ^ self readError:error.
     ].
     "
      arrive here if you try to receive into an invalid buffer (i.e. not ByteArray-like)
     "
     self primitiveFailed
-!
-
-receiveFrom:anAddressBuffer buffer:aDataBuffer
-    "receive datagramm data - put address of originating host into
-     anAddressBuffer, data into aBuffer.
-     Both must be ByteArray-like. The addressBuffer must
-     provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray).
-     Return the number of bytes received, or a negative number on error.
-     On error, the unix error code is left in the lastErrorNumber
-     instance variable."
-
-    ^ self receiveFrom:anAddressBuffer buffer:aDataBuffer start:1 for:(aDataBuffer size) flags:0
+
+    "Modified: / 21-03-2018 / 19:35:09 / stefan"
 !
 
-receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
-    ^ self receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes flags:0
+receiveFrom:aSocketAddress buffer:aDataBuffer
+    "receive datagramm data - put address of originating host into
+     aSocketAddress, data into aDataBuffer.
+     aDataBuffer must be ByteArray-like.
+     For backward compatibility, aSocketAddress may be a non-SocketAddress;
+     then, it must be a byteArray with appropriate size for the addressBytes.
+
+     Return the number of bytes received.
+     The thread blocks until data arrives - you may want to wait before
+     receiving, using #readWait or #readWaitWithTimeout:."
+
+    ^ self receiveFrom:aSocketAddress buffer:aDataBuffer start:1 for:(aDataBuffer size) flags:0
+
+    "Modified (comment): / 21-03-2018 / 19:33:59 / stefan"
 !
 
-receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes flags:flags
+receiveFrom:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes
+    ^ self receiveFrom:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes flags:0
+
+    "Modified (format): / 21-03-2018 / 19:32:27 / stefan"
+!
+
+receiveFrom:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes flags:flags
     "receive datagramm data
-     - put address of originating host into anAddressBuffer, data into aBuffer.
-     For backward compatibility, the addressBuffer may be a non-SocketAddress;
+     - put address of originating host into aSocketAddress, data into aDataBuffer.
+     aDataBuffer must be ByteArray-like.
+     For backward compatibility, aSocketAddress may be a non-SocketAddress;
      then, it must be a byteArray with appropriate size for the addressBytes.
 
-     Return the number of bytes received, or a negative number on error.
-     On error, the unix error code is left in the lastErrorNumber
-     instance variable.
+     Return the number of bytes received.
      The thread blocks until data arrives - you may want to wait before
      receiving, using #readWait or #readWaitWithTimeout:."
 
@@ -2525,17 +2528,17 @@
 
     domainClass := self class socketAddressClassForDomain:domain.
     domainClass isNil ifTrue:[
-	^ self error:'invalid (unsupported) domain'.
+        ^ self error:'invalid (unsupported) domain'.
     ].
-    anAddressBuffer isSocketAddress ifTrue:[
-	anAddressBuffer class == domainClass ifFalse:[
-	    ^ self error:'addressBuffer class mismatch (domain)'.
-	].
-	addr := anAddressBuffer.
+    aSocketAddress isSocketAddress ifTrue:[
+        aSocketAddress class == domainClass ifFalse:[
+            ^ self error:'addressBuffer class mismatch (domain)'.
+        ].
+        addr := aSocketAddress.
     ] ifFalse:[
-	anAddressBuffer notNil ifTrue:[
-	    addr := domainClass new.
-	].
+        aSocketAddress notNil ifTrue:[
+            addr := domainClass new.
+        ].
     ].
 
 %{
@@ -2543,103 +2546,103 @@
     OBJ fp = __INST(handle);
 
     if (fp != nil) {
-	SOCKET sock;
-	size_t objSize;
-	union sockaddr_u sa;
-	socklen_t alen = 0;
-	INT n, offs;
-	int _flags = __longIntVal(flags);
-	char *extPtr;
-	unsigned char *allocatedBuffer = NULL, *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;
+        size_t objSize;
+        union sockaddr_u sa;
+        socklen_t alen = 0;
+        INT n, offs;
+        int _flags = __longIntVal(flags);
+        char *extPtr;
+        unsigned char *allocatedBuffer = NULL, *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 = (INT)STX_WSA_NOINT_CALL6("recvfrom", recvfrom, sock, buffer, objSize, _flags, (struct sockaddr *)&sa, &alen);
-	} while ((n < 0) && (__threadErrno == EINTR));
-	if (n < 0) {
-	    errno = __threadErrno;
-	}
-
-	if (allocatedBuffer) {
-	    if (n > 0) {
-		memcpy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, n);
-	    }
-	    free(allocatedBuffer);
-	}
+        if (extPtr) {
+            buffer = extPtr + offs;
+        } else {
+            allocatedBuffer = buffer = (char *)malloc(objSize);
+        }
+
+        do {
+            __threadErrno = 0;
+            alen = sizeof(sa);
+            n = (INT)STX_WSA_NOINT_CALL6("recvfrom", recvfrom, sock, buffer, objSize, _flags, (struct sockaddr *)&sa, &alen);
+        } while ((n < 0) && (__threadErrno == EINTR));
+        if (n < 0) {
+            errno = __threadErrno;
+        }
+
+        if (allocatedBuffer) {
+            if (n > 0) {
+                memcpy((char *)__InstPtr(aDataBuffer) + offs, allocatedBuffer, 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
-		 */
-		memcpy(addrPtr, (char *)&sa, alen);
-		addrLen = __MKSMALLINT(alen);
-	    }
-	}
-	if (n < 0) {
-	    error = __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
+                 */
+                memcpy(addrPtr, (char *)&sa, alen);
+                addrLen = __MKSMALLINT(alen);
+            }
+        }
+        if (n < 0) {
+            error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
+        }
+        nReceived = __MKSMALLINT(n);
     }
 #endif
 bad: ;
 %}.
     error notNil ifTrue:[
-	^ self readError:error.
+        ^ self readError:error.
     ].
 
     nReceived notNil ifTrue:[
-	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
+        addrLen notNil ifTrue:[
+            (addr == aSocketAddress) ifFalse:[
+                self obsoleteFeatureWarning:'please use a socketAddress argument'.
+
+                "can be a ByteArray for backward compatibility"
+                aSocketAddress replaceFrom:1 to:addrLen with:(addr hostAddress).
+            ].
+        ].
+        ^ nReceived
     ].
     "
      arrive here if you try to receive into an invalid buffer
@@ -2648,15 +2651,13 @@
      or if the addressBuffer is nonNil AND too small.
     "
     self primitiveFailed
+
+    "Modified (comment): / 21-03-2018 / 19:33:49 / stefan"
 !
 
 sendBuffer:aDataBuffer start:startIndex for:nBytes flags:flags
-    "send data.
-     Both must be ByteArray-like. The bytes in the addressBuffer must
-     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
-     Return the number of bytes transmitted, or a negative number on error.
-     On error, the unix error code is left in the lastErrorNumber
-     instance variable."
+    "send data. aDataBuffer be ByteArray-like.
+     Return the number of bytes transmitted, or a negative number on error."
 
     |error|
 
@@ -2667,125 +2668,132 @@
     if ((fp != nil)
      && __isSmallInteger(startIndex)
      && __isSmallInteger(nBytes)) {
-	SOCKET sock;
-	INT objSize, n, offs;
-	char *extPtr;
-	int _flags = __longIntVal(flags);
-	unsigned long norder;
-	unsigned char *buffer, *allocatedBuffer = 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, n, offs;
+        char *extPtr;
+        int _flags = __longIntVal(flags);
+        unsigned long norder;
+        unsigned char *buffer, *allocatedBuffer = 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 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);
-	    memcpy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, objSize);
-	}
-
-	do {
-	    __threadErrno = 0;
-	    n = (INT)STX_WSA_NOINT_CALL4("send", send, sock, buffer, objSize, _flags);
-	} while ((n < 0) && (__threadErrno == EINTR));
-	if (n < 0) {
-	    errno = __threadErrno;
-	}
-
-	if (allocatedBuffer) {
-	    free(allocatedBuffer);
-	}
+        if (extPtr) {
+            buffer = extPtr + offs;
+        } else {
+            allocatedBuffer = buffer = (char *)malloc(objSize);
+            memcpy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, objSize);
+        }
+
+        do {
+            __threadErrno = 0;
+            n = (INT)STX_WSA_NOINT_CALL4("send", send, sock, buffer, objSize, _flags);
+        } while ((n < 0) && (__threadErrno == EINTR));
+        if (n < 0) {
+            errno = __threadErrno;
+        }
+
+        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) {
-	    error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
-	} else {
-	    RETURN (__MKSMALLINT(n));
-	}
+        if (n < 0) {
+            error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
+        } else {
+            RETURN (__MKSMALLINT(n));
+        }
     }
 #endif
 bad: ;
 %}.
     error notNil ifTrue:[
-	self writeError:error.
+        self writeError:error.
     ].
 
     "
      arrive here if you try to send from an invalid buffer (i.e. not ByteArray-like),
     "
     self primitiveFailed
+
+    "Modified: / 21-03-2018 / 19:22:52 / stefan"
 !
 
-sendTo:anAddressBuffer buffer:buffer
+sendTo:aSocketAddress buffer:buffer
     "send datagramm data - fetch address of destination host from
-     anAddressBuffer, data from aDataBuffer.
-     Both must be ByteArray-like. The bytes in the addressBuffer must
-     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
-     Return the number of bytes transmitted, or a negative number on error.
-     On error, the unix error code is left in the lastErrorNumber
-     instance variable.
-     Flags is currently ignored; it is there for ST-80 compatibility."
-
-    ^ self sendTo:anAddressBuffer buffer:buffer start:1 for:buffer size flags:0
+     aSocketAddress, data from aDataBuffer.
+     aDataBuffer must be ByteArray-like. 
+     aSocketAddress must be a valid SocketAddress for my domain 
+     (i.e. for IPv4, an IPSocketAddress).
+     For backward compatibility, a ByteArray is still supported in aSocketAddress
+     (i.e. for IPv4, a 4-byte byteArray).
+     Return the number of bytes transmitted."
+
+    ^ self sendTo:aSocketAddress buffer:buffer start:1 for:buffer size flags:0
+
+    "Modified (comment): / 21-03-2018 / 19:30:20 / stefan"
 !
 
-sendTo:anAddressBuffer buffer:buffer start:startIndex for:count
+sendTo:aSocketAddress buffer:buffer start:startIndex for:count
     "send datagramm data - fetch address of destination host from
-     anAddressBuffer, data from aDataBuffer.
-     Both must be ByteArray-like. The bytes in the addressBuffer must
-     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
-     Return the number of bytes transmitted, or a negative number on error.
-     On error, the unix error code is left in the lastErrorNumber
-     instance variable.
-     Flags is currently ignored; it is there for ST-80 compatibility."
-
-    ^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0
+     aSocketAddress, data from aDataBuffer.
+     aDataBuffer must be ByteArray-like. 
+     aSocketAddress must be a valid SocketAddress for my domain 
+     (i.e. for IPv4, an IPSocketAddress).
+     For backward compatibility, a ByteArray is still supported in aSocketAddress
+     (i.e. for IPv4, a 4-byte byteArray).
+     Return the number of bytes transmitted."
+
+    ^ self sendTo:aSocketAddress buffer:buffer start:startIndex for:count flags:0
+
+    "Modified (comment): / 21-03-2018 / 19:29:07 / stefan"
 !
 
-sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes flags:flags
+sendTo:aSocketAddress buffer:aDataBuffer start:startIndex for:nBytes flags:flags
     "send datagramm data - fetch address of destination host from
-     anAddressBuffer, data from aDataBuffer starting at startIndex,
+     aSocketAddress, data from aDataBuffer starting at startIndex,
      sending count bytes.
-     Both must be ByteArray-like. The bytes in the addressBuffer must
-     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
-     Return the number of bytes transmitted, or a negative number on error.
-     On error, the unix error code is left in the lastErrorNumber
-     instance variable."
+     aDataBuffer must be ByteArray-like. 
+     aSocketAddress must be a valid SocketAddress for my domain 
+     (i.e. for IPv4, an IPSocketAddress).
+     For backward compatibility, a ByteArray is still supported in aSocketAddress
+     (i.e. for IPv4, a 4-byte byteArray).
+     Return the number of bytes transmitted."
 
     |domainClass addr error|
 
-    anAddressBuffer isSocketAddress ifTrue:[
-	addr := anAddressBuffer.
+    aSocketAddress isSocketAddress ifTrue:[
+        addr := aSocketAddress.
     ] ifFalse:[
-	anAddressBuffer isByteArray ifFalse:[
-	    ^ self error:'bad socketAddress argument'
-	].
-	domainClass := self class socketAddressClassForDomain:domain.
-	domainClass isNil ifTrue:[
-	    ^ self error:'invalid (unsupported) domain'.
-	].
-	addr := domainClass hostAddress:anAddressBuffer.
+        aSocketAddress isByteArray ifFalse:[
+            ^ self error:'bad socketAddress argument'
+        ].
+        domainClass := self class socketAddressClassForDomain:domain.
+        domainClass isNil ifTrue:[
+            ^ self error:'invalid (unsupported) domain'.
+        ].
+        addr := domainClass hostAddress:aSocketAddress.
     ].
 %{
 #ifndef NO_SOCKET
@@ -2794,90 +2802,90 @@
     if ((fp != nil)
      && __isSmallInteger(startIndex)
      && __isSmallInteger(nBytes)) {
-	SOCKET sock;
-	INT objSize;
-	struct sockaddr *sockaddr_ptr;
-	union sockaddr_u sa;
-	socklen_t sockaddr_size, alen = 0;
-	INT sockAddrOffs;
-	INT n, offs;
-	char *extPtr;
-	int _flags = __longIntVal(flags);
-	unsigned long norder;
-	unsigned char *buffer;
-	unsigned char *allocatedBuffer = NULL;
-
-	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;
-	    }
-	    memcpy(&sa, (__byteArrayVal(addr) + sockAddrOffs), 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;
+        socklen_t sockaddr_size, alen = 0;
+        INT sockAddrOffs;
+        INT n, offs;
+        char *extPtr;
+        int _flags = __longIntVal(flags);
+        unsigned long norder;
+        unsigned char *buffer;
+        unsigned char *allocatedBuffer = NULL;
+
+        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;
+            }
+            memcpy(&sa, (__byteArrayVal(addr) + sockAddrOffs), 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);
-	    memcpy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, objSize);
-	}
-
-	do {
-	    __threadErrno = 0;
-	    n = (INT)STX_WSA_NOINT_CALL6("sendto", sendto, sock, buffer, objSize, _flags, sockaddr_ptr, sockaddr_size);
-	} while ((n < 0) && (__threadErrno == EINTR));
-	if (n < 0) {
-	    errno = __threadErrno;
-	}
-
-	if (allocatedBuffer) {
-	    free(allocatedBuffer);
-	}
+        if (extPtr) {
+            buffer = extPtr + offs;
+        } else {
+            allocatedBuffer = buffer = (char *)malloc(objSize);
+            memcpy(allocatedBuffer, (char *)__InstPtr(aDataBuffer) + offs, objSize);
+        }
+
+        do {
+            __threadErrno = 0;
+            n = (INT)STX_WSA_NOINT_CALL6("sendto", sendto, sock, buffer, objSize, _flags, sockaddr_ptr, sockaddr_size);
+        } while ((n < 0) && (__threadErrno == EINTR));
+        if (n < 0) {
+            errno = __threadErrno;
+        }
+
+        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) {
-	    error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
-	} else {
-	    RETURN (__MKSMALLINT(n));
-	}
+        if (n < 0) {
+            error = __INST(lastErrorNumber) = __MKSMALLINT(errno);
+        } else {
+            RETURN (__MKSMALLINT(n));
+        }
     }
 #endif
 bad: ;
 %}.
     error notNil ifTrue:[
-	self writeError:error.
+        self writeError:error.
     ].
 
     "
@@ -2887,6 +2895,8 @@
      or if the addressBuffer is nonNil AND too small.
     "
     self primitiveFailed
+
+    "Modified: / 21-03-2018 / 19:27:51 / stefan"
 ! !
 
 !Socket methodsFor:'error reporting'!
@@ -3886,6 +3896,7 @@
     "
 ! !
 
+
 !Socket methodsFor:'specials'!
 
 linger:anIntegerOrNil
@@ -4219,6 +4230,7 @@
     ^ self setSocketOption:#'TCP_NODELAY' argument:aBoolean argument:nil.
 ! !
 
+
 !Socket methodsFor:'waiting'!
 
 waitForNewConnectionOrDataOnAny:otherConnections timeout:secondsOrTimeDurationOrNil