If you call recv() to fetch data, the syscall will block if nothing happens. But what are the constraints for tcp_recvmsg() to return? This posting focus on the major factors (other aspects like OOB data, signals, non-blocking IO is ignored in this posting):
- Amount of data
tcp_recvmsg() first calculate the timeout for this function via sock_rcvtimeo(). This refers to return noblock ? 0 : sk->sk_rcvtimeo - in the common therefore sk->sk_rcvtimeo. This is initialized as MAX_SCHEDULE_TIMEOUT (LONG_MAX).
On the other hand sock_rcvlowat() calculate the minimum amount of data. If the user specify MSG_WAITALL then the minimum is the length argument. In all other cases sock_rcvlowat() uses sk_rcvlowat. That values is standard 1, but can be changes via setsockopts(SO_RCVLOWAT). After all the minimum amount refers to 1 byte!
tcp_recvmsg() will now peek the skbuffs until the amount the data is >= 1. If there is no data available (no one send something) the process sleep until some data is send. Naturally the code doesn't read explicit 1 byte. skb_peek() is greedy! Normally you recvmsg() will return with all data which is instantly available.
After all: tcp_recvmsg() will block forever until one byte of data is available!