Subclassing socket
Steve Holden
steve at holdenweb.com
Sat Jan 14 03:26:51 EST 2006
groups.20.thebriguy at spamgourmet.com wrote:
> Steve,
>
> To your question of why you'd ever receive value:
>
> This is very common in any network programming. If you send a packet
> of data that has a header and payload, and the header contains the
> length (N) of the payload, then at some point you have to receive N
> bytes. If N is zero, then you receive 0 bytes. Of course, you CAN
> test for N == 0, that's obvious - but why would you if the underlying
> layers worked correctly? Its just extra code to handle an special case.
>
I understand all that, but you are presumably also aware that a
zero-length result from recv() indicates that the other party to a TCP
connection has closed their end of the socket?
Given that information, it's hard to know why you would ever really want
to recv(0), since the presumably empty return string would effectively
prohibit you form detecting that condition.
So I'd suggest a test for a requirement of zero bytes, with a
corresponding skip of the recv() call in those cases, at least for TCP.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list