Menu

#5 sendmsg and recvmsg should allow zero-length datagrams

0.1
open
Tetsujin
None
2017-07-08
2017-07-08
Tetsujin
No

The current versions of sendmsg and recvmsg are based on assumptions that are valid when the socket is of type SOCK_STREAM, which treats the socket as a bytestream and doesn't provide message boundaries (mostly). In particular, sendmsg rejects any attempt to send a zero-length message, and recvmsg treats a zero-length receive as end-of-file.

In SOCK_DGRAM and SOCK_SEQPACKET sockets, however, the data stream is delimited by message boundaries. It is possible (and valid) in these socket types to store zero-length messages.

The issue is complicated somewhat by a bug on Linux: recvmsg is supposed to return the MSG_EOR flag if a read ends at a message boundary. On Linux, however, this seems not to happen, so the caller can't readily distinguish between reading a zero-length message and reaching the end of the stream.

Acceptance Criteria
sendmsg should allow sending zero-length messages over SOCK_DGRAM and SOCK_SEQPACKET sockets: Zero-length messages on SOCK_STREAM are still considered invalid.
recvmsg should correctly handle receiving zero-length messages over SOCK_DGRAM and SOCK_SEQPACKET sockets: A zero-length read on SOCK_STREAM still indicates end-of-file. For datagram and seqpacket sockets, another method will be required to distinguish between zero-length packets and end-of-file.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB