For IPv4, TCP at least accepts on Linux, MSG_WAITALL is ignored if MSG_NONBLOCK is specified (or the file descriptor is set to non-blocking).
From tcp_recvmsg () to net / ipv4 / tcp.c in the Linux kernel:
if (copied >= target && !sk->sk_backlog.tail) break; if (copied) { if (sk->sk_err || sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN) || !timeo || signal_pending(current)) break;
purpose
for this cast is set for the requested size if MSG_DONTWAIT is specified or some lower value (at least 1) if not. The function will end if:
- A sufficient number of bytes have been copied.
- Socket error
- The socket was closed or turned off
- timeo is 0 (socket is set to non-blocking)
- Signal Awaiting Process
It seems to me that this may be a bug in Linux, but in any case, it will not work the way you want. It looks like the dec-vt100 solution will be, but there is a race condition if you are trying to get from the same socket in several processes or threads.
That is, another call to recv () by another thread / process may occur after your thread has done a peek, causing your thread to block the second recv ().
Matt
source share