#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Wed, 08 Apr 2020 18:18:58 +0200
changeset 5472 b1822258a4be
parent 5471 0bee7a5e40e8
child 5473 de911f462862
#REFACTORING by stefan class: Socket class definition changed: #receiveFrom:buffer:start:for:flags:
Socket.st
--- a/Socket.st	Fri Apr 03 18:50:48 2020 +0200
+++ b/Socket.st	Wed Apr 08 18:18:58 2020 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1992 by Claus Gittinger
               All Rights Reserved
@@ -145,16 +143,14 @@
         char *extPtr = 0;
         int sIdx = 0, objSize = 0, offs = 0;
 
-        sIdx = 0;
         if (__isSmallInteger(startIndex)) {
             sIdx = __intVal(startIndex) - 1;
         }
 
         if (__isExternalBytesLike(aDataBuffer)) {
-            OBJ sz;
+            OBJ sz = __externalBytesSize(aDataBuffer);
 
             extPtr = (char *)(__externalBytesAddress(aDataBuffer));
-            sz = __externalBytesSize(aDataBuffer);
             if (__isSmallInteger(sz)) {
                 objSize = __intVal(sz);
             } else {
@@ -162,11 +158,9 @@
             }
             offs = sIdx;
         } else {
-            OBJ oClass;
+            OBJ oClass __Class(aDataBuffer);
             int nInstVars, nInstBytes;
 
-            extPtr = (char *)0;
-            oClass = __Class(aDataBuffer);
             switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
                 case BYTEARRAY:
                     offs = sIdx;
@@ -2664,7 +2658,7 @@
         if (extPtr) {
             buffer = extPtr + offs;
         } else {
-            allocatedBuffer = buffer = (char *)malloc(objSize);
+            allocatedBuffer = buffer = (unsigned char *)malloc(objSize);
         }
 
         do {
@@ -2695,28 +2689,25 @@
         __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 && __isNonNilObject(addr)) {
+            char *addrPtr;
+            int nInstVars, nInstBytes, objSize;
+            OBJ 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);
@@ -2731,13 +2722,11 @@
     ].
 
     nReceived notNil ifTrue:[
-        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).
-            ].
+        (addrLen notNil and:[addr ~~ aSocketAddress]) ifTrue:[
+            self obsoleteFeatureWarning:'please use a socketAddress argument'.
+
+            "can be a ByteArray for backward compatibility"
+            aSocketAddress replaceFrom:1 to:addrLen with:(addr hostAddress).
         ].
         ^ nReceived
     ].
@@ -2749,7 +2738,7 @@
     "
     self primitiveFailed
 
-    "Modified (comment): / 21-03-2018 / 19:33:49 / stefan"
+    "Modified: / 06-04-2020 / 22:33:10 / stefan"
 !
 
 sendBuffer:aDataBuffer start:startIndex for:nBytes flags:flags