The python3 socket programming howto presents this code snippet
class MySocket:
\"\"\"demonstration class only
- coded for clarity, not efficiency
Upon seeing the question I was somehow stunned, because a send
C call can return 0 bytes and the connection is of course still alive (the socket cannot simply send more bytes at that given moment in time)
I decided to "use the source" and unless I am very wrong (which can always be and often is) this is a bug in the HOWTO.
Chain:
send
is an alias for sock_send
sock_send
calls in turn sock_call
sock_call
calls in turn sock_call_ex
sock_call
calls in turn sock_send_impl
(which has been passed down the chain starting with sock_send
)Unwinding:
sock_send_impl
returns true
or false
(1 or 0) with return (ctx->result >= 0)
sock_call_ex
returns
-1
if sock_send_impl
returns false
0
if sock_send_impl
returns true
sock_call
returns this value transparently.
sock_send
returns NULL
for a -1
(because an error has been set and an exception will be raised)
returns ctx->result
for 0
from sock_call
And ctx->result
is the number of bytes written by the C call send
in sock_send_impl
.
The chain shows that if 0
bytes have been sent, there is no error and this actually is a potential real life socket situation.
If my logic is wrong, someone please let me know.