nik
nik

Reputation: 8745

Python socket.sendall() function

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?

Upvotes: 16

Views: 20432

Answers (2)

Nemo
Nemo

Reputation: 71535

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.

Upvotes: 14

cababunga
cababunga

Reputation: 3114

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".

Upvotes: 6

Related Questions