I'm reading Tutorial on Network Programming with Python, and in this document the author is saying that "The function sendall() should be used only with blocking sockets."
But I do not see any such condition in the Python documentation, socket.sendall(string[, flags]).
Is the author of PyNet right?
Upon successful completion, accept() shall return the non-negative file descriptor of the accepted socket. Otherwise, -1 shall be returned and errno set to indicate the error.
The recv() function shall return the length of the message written to the buffer pointed to by the buffer argument. For message-based sockets, such as SOCK_DGRAM and SOCK_SEQPACKET, the entire message shall be read in a single operation.
The recvfrom() function receives data on a socket named by descriptor socket and stores it in a buffer. The recvfrom() function applies to any datagram socket, whether connected or unconnected. The socket descriptor. The pointer to the buffer that receives the data.
You can use the function connect_ex. It doesn't throw an exception. Instead of that, returns a C style integer value (referred to as errno in C): s = socket.
When in doubt, check the source.
socket_sendall
clearly gives up once send() returns -1, which it will do (with errno of EAGAIN or EWOULDBLOCK) if you call it on a non-blocking socket without calling poll() or select(). (And the internal_select
function skips calling poll()/select() when the socket is non-blocking.)
So I would say the PyNet author is correct.
sendall() doesn't make sense on non-blocking socket. It has to block if it can't send all data at once, otherwise it wouldn't be called "sendall".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With