The behaviour of recv
/read
depends on the characteristics of the socket itself. If the socket is marked as non-blocking, these calls should immediately return EAGAIN
/EWOULDBLOCK
rather than blocking the process.
The socket can be marked as non-blocking prior to reading from it, usually via fcntl
or ioctl
.
What this excerpt from the manual says is that, basically, reads on both blocking and non-blocking sockets are not required to fill the whole buffer that is supplied. That is why it is important to check the result of the recv
/read
calls in order to know how much of the buffer contains the actual data and how much is garbage.
It is not a good idea at all to use blocking sockets in conjunction with the IO polling calls such as select
/poll
/epoll
. Even if the polling call indicates that a particular socket is ready for reading, a blocking socket would sometimes still block.