Mantis - Squeak
Viewing Issue Advanced Details
6951 Network major always 02-26-08 03:32 02-26-08 03:32
kwl  
cdegroot  
low  
assigned 3.10  
open  
none    
none  
0006951: #waitForData* and senders have misleading comments resp. implementation
#receiveDataTimeout:into:startingAt: sends #waitForDataFor:ifClosed:ifTimedOut: with empty blocks, that is: no exception if thrown even if the request is made to a Socket which is disconnected on this side (case 1). Also, the status is reported 'otherEndClosedButNotThisEnd' (see below) as the wrong direction.

Moreover, #waitForData: and #waitForDataFor:ifClosed:ifTimedOut: would signal ConnectionClosed only if the socket is closed _on_this_side_ *before* the respective message is sent (case 2).

In both cases in the below, no exception is signaled at all.
Case 1, no exception when this side is disconnected and #receiveData* it sent:
 | localhost serverSocket clientSocket worker |

 localhost := NetNameResolver localHostAddress.
"warning" Socket allInstancesDo: [:socket | socket destroy].
 serverSocket := Socket newTCP listenOn: 7680.
 clientSocket := Socket newTCP connectTo: localhost port: 7680.
 [clientSocket disconnect] on: Exception do: [:ex|].
 (Delay forMilliseconds: 125) wait.
 worker := [clientSocket receiveDataTimeout: 1 into: (ByteArray new: 1) startingAt: 1] forkAt: Processor activeProcess priority.
 (Delay forMilliseconds: 125) wait.
 Transcript cr; show: serverSocket statusString, ' [server]';
    cr; show: clientSocket statusString, ' [client], dataAvailable: '
        , clientSocket dataAvailable storeString;
    cr; show: 'worker: ', worker browserPrintString.
 [clientSocket destroy] on: Exception do: [:ex|].
 [serverSocket destroy] on: Exception do: [:ex|]
======>
connected [server]
otherEndClosedButNotThisEnd [client], dataAvailable: false
worker: (40s) 3850: Process>>terminate
----------------------
Case 2: no exception when waiting for data and other side disconnects:
 | localhost serverSocket sessionSocket clientSocket worker |

 localhost := NetNameResolver localHostAddress.
"warning" Socket allInstancesDo: [:socket | socket destroy].
 serverSocket := Socket newTCP listenOn: 7680 backlogSize: 1.
 clientSocket := Socket newTCP connectNonBlockingTo: localhost port: 7680.
 sessionSocket := serverSocket waitForAcceptFor: 1.
 worker := [sessionSocket waitForDataFor: 1"; receiveSomeDataInto: (ByteArray new: 1)"] forkAt: Processor activeProcess priority.
 (Delay forMilliseconds: 125) wait.
 Transcript cr; show: serverSocket statusString, ' [server]';
    cr; show: clientSocket statusString, ' [client]';
    cr; show: sessionSocket statusString, ' [session], dataAvailable: '
        , sessionSocket dataAvailable storeString;
    cr; show: 'worker: ', worker browserPrintString.
 [clientSocket disconnect] on: Exception do: [:ex|].
 (Delay forMilliseconds: 125) wait.
 Transcript cr; show: serverSocket statusString, ' [server]';
    cr; show: clientSocket statusString, ' [client]';
    cr; show: sessionSocket statusString, ' [session], dataAvailable: '
        , sessionSocket dataAvailable storeString;
    cr; show: 'worker: ', worker browserPrintString; cr.
 [sessionSocket destroy] on: Exception do: [:ex|].
 [clientSocket destroy] on: Exception do: [:ex|].
 [serverSocket destroy] on: Exception do: [:ex|]
======>
waitingForConnection [server]
connected [client]
connected [session], dataAvailable: false
worker: (40) 2124: Semaphore>>waitTimeoutMSecs:
waitingForConnection [server]
unconnected [client]
connected [session], dataAvailable: true
worker: (40s) 2124: Process>>terminate

There are no notes attached to this issue.