send()
shall return the number of bytes sent or error code, but all examples that I found check it only with error codes, but not with the number of bytes sent.
//typical example
int cnt=send(s,query,strlen(query),0);
if (cnt < 0) return(NULL);
//Hey, what about cnt < strlen(query)?
Q: Does "send()" always return the whole buffer?
A: No, not necessarily.
From Beej's Guide: * http://beej.us/guide/bgnet/html/multi/syscalls.html#sendrecv
Q: Does "recv()" always read the whole buffer?
A: No, absolutely not. You should never assume the buffer you've received is "the whole message". Or assume the message you receive is from one, single message.
Here's a good, short explanation. It's for Microsoft/C#, but it's applicable to all sockets I/O, in any language:
The answer is in another section of
man 2 send
:Or, alternatively, the POSIX version (
man 3p send
):So, while a
read
of partial data is common, a partialsend
in blocking mode should not happen (barring implementation details).Nope, it doesn't.
For reference, see the man page for send: