From the recv(2) man page:
MSG_WAITALLThis flag requests that the operation block until the full request is satisfied. However, the call may still return less data than requested if a signal is caught, an error or disconnect occurs, or the next data to be received is of a different type than that returned.
It doesn’t look like there’s an equivalent flag for send(2), which strikes me as strange. Maybe send()s are guaranteed to always accept the whole buffer, but I don’t see that written anywhere (and anyway, that seems unlikely to me).
Is there a way to tell send() to wait until it’s sent the whole buffer before returning, equivalently to recv()‘s MSG_WAITALL?
Edit: I understand that send() just copies data into a buffer in the operating system and that I can’t force send() to put data onto the wire. My question is: Can I force send() to block until all the data I gave it has been copied into the OS’s buffer?
You can’t.
sendjust offloads the buffer to the kernel, then returns.To quote from the Unix standard:
Note the word “initiate”. It doesn’t actually send anything, rather tells the OS to send the message when it’s ready for it (when its buffers are full or after some time has passed).