Strange socket behavior

John M McIntosh johnmci at smalltalkconsulting.com
Tue Oct 3 04:52:54 UTC 2006


On 2-Oct-06, at 8:01 PM, Andreas Raab wrote:

>   data := ByteArray new: 10000000.
>   socket := Socket newTCP.
>   socket connectTo: 'myHost' port: myPort.
>   socket sendData: data count: count.
>   socket sendData: 'Hello' count: 5.


You mean a example like

serverAddr := NetNameResolver addressForName: 'localhost' timeout:  
54323.
count := 10000000.
>  data := ByteArray new: count.
>   socket := Socket newTCP.
>   socket connectTo: serverAddr port: myPort.
>   socket sendData: data count: count.
>   socket sendData: 'Hello' count: 5.


man send

Depending on your flavor of unix it may or may not allow you to grab  
10,000,000 bytes of storage.
If it does then

    If no messages space is available at the socket to hold the  
message to be
      transmitted, then send() normally blocks, unless the socket has  
been
      placed in non-blocking I/O mode.  The select(2) call may be  
used to
      determine when it is possible to send more data.

We don't run the socket in non-blocking mode so the socket will block  
if there isn't space to transmit the message. 10MB will block and  
timeout I note if I don't read the data on the server, but at 100K it  
will cheerfully accept and say it sent the bytes, how much it will  
accept before blocking is dependent on window size etc, likely my  
home gigabit infranet  (RFC 1323) is configured to allow lots of  
bytes in flight btw, so other networks might abort at 100K.  Iin this  
case the socket won't block  until I've sent the agreed window size  
of data which is > 100K

We have no idea if the data has been received by the other side yet,  
and if sending to Mars we still have many minutes to wait.

One problem people have encounter in the past is sending oh say 64K  
then closing the socket on a slow connection, the socket *lingers*  
around open for the linger time for a few seconds after the close  
request to flush any data, but on a slow connection this linger time  
is insufficient to ensure all the data is transmitted beofre the  
close.  If your model is send 10MB, then close the socket, I suspect  
it's terminating before the data is fully sent on unix based machines.

btw sqSocketSendDone on the unix platforms checks to see if sending  
more data would block if not then it says the send is done, which  
isn't quite true since the send might not be done because send done  
doesn't mean all the bytes are sent and delivered to the remote host,  
that is a different question.

sendDone ~= messageDelivered


--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===





More information about the Squeak-dev mailing list