class: Socket
authorStefan Vogel <sv@exept.de>
Wed, 16 Apr 2014 10:33:22 +0200
changeset 3224 bad706c50347
parent 3223 b126729a904b
child 3225 a10937a309bb
class: Socket added: #finalize #linger: Discard buffered data when finalizing a socket
Socket.st
--- a/Socket.st	Fri Apr 11 10:31:25 2014 +0200
+++ b/Socket.st	Wed Apr 16 10:33:22 2014 +0200
@@ -2004,6 +2004,11 @@
 
 !Socket methodsFor:'closing'!
 
+finalize
+    self linger:0.      "/ discard buffered data
+    super finalize.
+!
+
 shutDown
     "shutDown and close the socket"
 
@@ -3724,6 +3729,21 @@
 
 !Socket methodsFor:'specials'!
 
+linger:anIntegerOrNil 
+    "set the linger behavior on close:
+      anIntegerOrNil == nil: close returns immediately, socket tries
+                             to send buffered data in background.
+      anIntegerOrNil == 0:   close returns immediately, bufferd data is discarded.
+      anIntegerOrNil > 0:    close waits this many seconds for buffered data
+                             to be delivered, after this time buffered data is
+                             discarded and close returns"
+    
+    ^ self 
+        setSocketOption:#'SO_LINGER'
+        argument:anIntegerOrNil notNil
+        argument:anIntegerOrNil.
+!
+
 receiveBufferSize
     "get the send buffer size - for special applications only.
      Not all operatingSystems offer this functionality
@@ -4078,10 +4098,10 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.301 2014-04-11 08:31:25 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.302 2014-04-16 08:33:22 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.301 2014-04-11 08:31:25 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.302 2014-04-16 08:33:22 stefan Exp $'
 ! !