MSG_WAITALL and recv
The recv() function has a really rare argument: MSG_WAITALL. It tells that the syscall should not return before length bytes are read. The problem is that normally nobody knows how much data is send by the peer node. So if you rely on a particular amount of data and the data isn't send, this call blocks infinity! On the other hand, a programmer must also handle this kind of failure, because a simple read() of a socket can also block forever. A timeout handler is always needed (alarm() as the simplest solution).
The background is that recv() normally return after length bytes or if a threshold values is raised. sock_rcvlowat() is the function who look if the user want to wait until length bytes are ready or returns earlier. sk_rcvlowat is the socket specific variable which determine the break out szenario.
return (waitall ? len : min_t(int, sk->sk_rcvlowat, len)) ? : 1;
sk_rcvlowat can be set on a socket basis via setsockopt(). Normally sk_rcvlowat is initialized with 1. Therefore a recv() call does block minimum for 1 byte. If you increase sk_rcvlowat beyond the recv() length parameter then min(sk_rcvlowat, length) -> length is taken - of course!
recv() will also return if OOB data is received, an error occured or an signal arrived us.