can I read exactly one UDP packet off a socket?

Posted by Brian Palmer on Stack Overflow See other posts from Stack Overflow or by Brian Palmer
Published on 2010-03-30T18:21:30Z Indexed on 2010/03/30 18:23 UTC
Read the original article Hit count: 331

Filed under:
|

Using UNIX socket APIs on Linux, is there any way to guarantee that I read one UDP packet, and only one UDP packet? I'm currently reading packets off a non-blocking socket using recvmsg, with a buffer size a little larger than the MTU of our internal network. This should ensure that I can always receive the full UDP packet, but I'm not sure I can guarantee that I'll never receive more than one packet per recvmsg call, if the packets are small.

The recvmsg man pages reference the MSG_WAITALL option, which attempts to wait until the buffer is filled. We're not using this, so does that imply that recvmsg will always return after one datagram is read? Is there any way to guarantee this?

Ideally I'd like a cross-UNIX solution, but if that doesn't exist is there something Linux specific?

© Stack Overflow or respective owner

Related posts about udp

Related posts about c