--- a/Socket.st Sat Oct 15 06:56:28 2016 +0200
+++ b/Socket.st Wed Oct 19 06:53:17 2016 +0200
@@ -2012,13 +2012,19 @@
!Socket methodsFor:'closing'!
-finalize
- self linger:0. "/ discard buffered data
- super finalize.
+abortAndClose
+ "immediately abort the connection:
+ discard buffered data and close the stream"
+
+ self linger:0.
+ self close.
!
shutDown
- "shutDown and close the socket"
+ "shutDown (initiate a graceful close)
+ and close (free the filedescriptor) the socket.
+ The close will return immediately and buffered data will be sent in the
+ background, unless you set linger"
self shutdown:2.
self close
@@ -2036,8 +2042,11 @@
shutDownOutput
"shutDown the output side of the socket.
Any write to the socket will signal end-of-file from now on.
- An orderly realease (TCP FIN) will be initiated after the last buffered data
- has been sent, so the other side will get a end-of-file condition eventually."
+ An orderly release (TCP FIN) will be initiated after the last buffered data
+ has been sent, so the other side will get a end-of-file condition eventually.
+ If you set linger > 0, the operation will wait until buffered data
+ has been delivered to the peer.
+ Otherwise the operation returns immediately."
self shutdown:1.
! !
@@ -2808,6 +2817,13 @@
self primitiveFailed
! !
+!Socket methodsFor:'finalization'!
+
+finalize
+ self linger:0. "/ do an abortive release - discard buffered data
+ self closeFile. "/ does not wait due to abortive release.
+! !
+
!Socket methodsFor:'initialization'!
initialize
@@ -2816,73 +2832,6 @@
eolMode := nil.
! !
-!Socket protectedMethodsFor:'low level'!
-
-closeFile
- "low level close - may be redefined in subclasses
- Don't send this message, send #close instead"
-
- |fp error|
-
- fp := handle.
-
-%{
- int rslt;
-
- if (fp == nil) {
- error = @symbol(errorNotOpen);
- goto out;
- }
-
- if (__INST(handleType) == @symbol(socketHandle)) {
- SOCKET socket = SOCKET_FROM_FILE_OBJECT(fp);
-
- if (@global(FileOpenTrace) == true) {
- console_fprintf(stderr, "close socket [ExternalStream] %"_lx_"\n", socket);
- }
-
- // whether the close() will be successful or not - the handle is invalid now!
- __INST(handle) = nil;
- do {
-#ifdef __win32__
- rslt = __STX_WSA_NOINT_CALL1("closesocket", closesocket, socket);
-#else
- rslt = close(socket);
-#endif
- } while((rslt < 0) && (__threadErrno == EINTR));
- if (rslt == 0) {
- RETURN(self);
- }
- error = __mkSmallInteger(__threadErrno);
- }
-
-out:;
-%}.
-
- error notNil ifTrue:[
- error == #errorNotOpen ifTrue:[
- self errorNotOpen.
- ].
- error isInteger ifTrue:[
- lastErrorNumber := error.
- self writeError:error.
- ^ self.
- ].
- self primitiveFailed:error.
- ^ self.
- ].
-
- super closeFile.
-
- "/ fallback for rel5
-
- fp := handle.
- fp notNil ifTrue:[
- handle := nil.
- self closeFile:fp
- ]
-! !
-
!Socket methodsFor:'low level'!
getSocketAdress
@@ -3835,16 +3784,16 @@
linger:anIntegerOrNil
"set the linger behavior on close:
anIntegerOrNil == nil: close returns immediately, socket tries
- to send buffered data in background.
+ 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"
+ to be delivered, after this time buffered data is
+ discarded and close returns with an error"
^ self
- setSocketOption:#'SO_LINGER'
- argument:anIntegerOrNil notNil
- argument:anIntegerOrNil.
+ setSocketOption:#'SO_LINGER'
+ argument:anIntegerOrNil notNil
+ argument:anIntegerOrNil.
!
receiveBufferSize