#QUALITY by stefan
authorStefan Vogel <sv@exept.de>
Tue, 03 Mar 2020 16:22:24 +0100
changeset 5464 7f31945df4b1
parent 5463 c6a3af27138d
child 5465 52c1146e9b95
#QUALITY by stefan class: Socket added: #isSocket comment/format in: #nonBlockingNextPutAll: #primNonBlockingNextPutAll: #setNonBlocking changed: #printOn: #printOn - print if socket is closed
Socket.st
--- a/Socket.st	Mon Mar 02 20:40:22 2020 +0100
+++ b/Socket.st	Tue Mar 03 16:22:24 2020 +0100
@@ -3600,6 +3600,9 @@
 
 printOn:aStream
     aStream nextPutAll:self className; nextPutAll:'('.
+    self isOpen ifFalse:[
+        aStream nextPutAll:'*closed* '.
+    ].    
     domain printOn:aStream.
     aStream nextPutAll:' protocol='.
     protocol printOn:aStream.
@@ -3620,6 +3623,7 @@
 
     "Modified: / 23-04-2018 / 19:44:24 / stefan"
     "Modified: / 19-09-2018 / 18:30:20 / Claus Gittinger"
+    "Modified: / 02-03-2020 / 19:25:40 / Stefan Vogel"
 ! !
 
 !Socket methodsFor:'queries'!
@@ -4032,7 +4036,6 @@
     "
 ! !
 
-
 !Socket methodsFor:'specials'!
 
 linger:anIntegerOrNil
@@ -4398,12 +4401,13 @@
             countRemainingBytesToWrite := bytes size.
         ].
 
-        "/ timeout does not matter, we wait infinitiv (due to loop)   
+        "/ timeout does not matter, we wait indefinitely (due to loop)   
         self writeWaitWithTimeoutMs:1000.
     ].
 
     "Created: / 30-01-2020 / 16:35:08 / Stefan Reise"
     "Modified (format): / 06-02-2020 / 13:18:59 / Stefan Reise"
+    "Modified (comment): / 03-03-2020 / 15:25:26 / Stefan Vogel"
 !
 
 primNonBlockingNextPutAll:someBytes
@@ -4427,34 +4431,34 @@
     "
     returnValue := -1. 
 
-    %{
+%{
 # ifdef __win32__
-        // ALWAYS check for proper arguments, please
-        OBJ fp = __INST(handle);
-
-        if (__isExternalAddress(bytes)
-         && __isSmallInteger(byteLength)
-         && (fp != NULL)) {
-            int sendResult;
-            int wsaErrorNo;
-            char *pBytes = __externalAddressVal(bytes);
-            SOCKET socket = SOCKET_FROM_FILE_OBJECT(fp);
-
-            sendResult = send(socket, pBytes, __intVal(byteLength), 0);
-            if (sendResult == SOCKET_ERROR) {
-                wsaErrorNo = WSAGetLastError();
-                if (wsaErrorNo == WSAEWOULDBLOCK) {
-                    returnValue = __MKSMALLINT(0);
-                } else {
-                    console_printf("send failed with: %d\n", wsaErrorNo);
-                    wsaError = __MKSMALLINT(wsaErrorNo);           
-                }
+    // ALWAYS check for proper arguments, please
+    OBJ fp = __INST(handle);
+
+    if (__isExternalAddress(bytes)
+     && __isSmallInteger(byteLength)
+     && (fp != NULL)) {
+        int sendResult;
+        int wsaErrorNo;
+        char *pBytes = __externalAddressVal(bytes);
+        SOCKET socket = SOCKET_FROM_FILE_OBJECT(fp);
+
+        sendResult = send(socket, pBytes, __intVal(byteLength), 0);
+        if (sendResult == SOCKET_ERROR) {
+            wsaErrorNo = WSAGetLastError();
+            if (wsaErrorNo == WSAEWOULDBLOCK) {
+                returnValue = __MKSMALLINT(0);
             } else {
-                returnValue = __MKSMALLINT(sendResult);
+                console_printf("send failed with: %d\n", wsaErrorNo);
+                wsaError = __MKSMALLINT(wsaErrorNo);           
             }
+        } else {
+            returnValue = __MKSMALLINT(sendResult);
         }
+    }
 #endif // __win32__
-    %}.
+%}.
 
     returnValue < 0 ifTrue:[
         WriteError raiseWith:wsaError.   
@@ -4462,8 +4466,7 @@
 
     ^ returnValue
 
-    "Created: / 30-01-2020 / 16:36:01 / Stefan Reise"
-    "Modified: / 17-02-2020 / 15:31:14 / Stefan Reise"
+    "Modified: / 03-03-2020 / 15:29:09 / Stefan Vogel"
 !
 
 setNonBlocking
@@ -4478,36 +4481,42 @@
         ^ self
     ].
 
-    %{
+%{
 # ifdef __win32__
-        // ALWAYS check for proper arguments, please
-        OBJ fp = __INST(handle);
-
-        if (fp != NULL) {
-            int result;
-            u_long nonBlocking = 1;
-            SOCKET socket = SOCKET_FROM_FILE_OBJECT(fp);
-
-            result = ioctlsocket(socket, FIONBIO, &nonBlocking);
-            if (result == SOCKET_ERROR) {
-                console_fprintf(stderr, "Win32OS [info]: ioctlsocket failed with %d\n", WSAGetLastError());
-                RETURN(false);
-            }
-
-            RETURN(true);
+    // ALWAYS check for proper arguments, please
+    OBJ fp = __INST(handle);
+
+    if (fp != NULL) {
+        int result;
+        u_long nonBlocking = 1;
+        SOCKET socket = SOCKET_FROM_FILE_OBJECT(fp);
+
+        result = ioctlsocket(socket, FIONBIO, &nonBlocking);
+        if (result == SOCKET_ERROR) {
+            console_fprintf(stderr, "Win32OS [info]: ioctlsocket failed with %d\n", WSAGetLastError());
+            RETURN(false);
         }
+
+        RETURN(true);
+    }
 #endif // __win32__
-    %}.
+%}.
 
     self primitiveFailed.
 
-    "Created: / 06-02-2020 / 13:09:42 / Stefan Reise"
+    "Modified: / 03-03-2020 / 15:29:26 / Stefan Vogel"
 ! !
 
 !Socket methodsFor:'testing'!
 
 isSSLSocket
     ^ false
+!
+
+isSocket
+    ^ true
+
+    "Created: / 03-03-2020 / 15:52:09 / Stefan Vogel"
 ! !
 
 !Socket methodsFor:'waiting'!