select.select and socket.setblocking

Francesco Bochicchio bockman at virgilio.it
Wed Dec 31 11:39:32 CET 2008


Francesco Bochicchio ha scritto:
>>
>> No, in blocking mode it will wait to receive _some_ data (1 or
>> more bytes).  The "requested" amount is strictly an upper
>> limit: recv won't return more than the requested number of
>> bytes, but it might return less.
>>
> 
> Uhm. In my experience, with TCP protocol recv only returned less than 
> the required bytes if the remote end disconnects. I always check the
> returned value of recv and signal an error if the read bytes are less 
> than the expected ones, but this error is never occurred (and its about 
> 20 years that I use sockets in various languages and various flavor of 
> unix and occasionally on windows. Maybe  have always been lucky ? :-)
> 

BTW, this is not a rethorical or ironic question... my applications 
mostly run on LANs or dedicated WANs so maybe they never experienced the
kind of network congestion that could cause recv to return less than the 
expected amount of bytes ...

but then, IIRC TCP guarantees that the packet is fully received by 
hand-shaking at transport level between sender and receiver. Ad once the 
packet is fully in the receiver buffer, why should recv choose to give
back to the application only a piece of it?

Ciao
-----
FB



More information about the Python-list mailing list