Matthew Dempsky <matt...@dempsky.org> writes: > On Wed, May 14, 2014 at 4:58 AM, Jérémie Courrèges-Anglas > <j...@wxcvbn.org> wrote: >> if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) && >> cmsg->cmsg_level == SOL_SOCKET && >> cmsg->cmsg_type == SCM_RIGHTS) { >> passed_fd = *(int *)CMSG_DATA(cmsg); > > In your test program you only ever send one FD, so this is fine; but > in general multiple FDs can be sent at a time, and you'll receive a > single SOL_SOCKET/SCM_RIGHTS control message with an array of N ints. > > E.g., see > https://code.google.com/p/chromium/codesearch#chromium/src/base/posix/unix_domain_socket_linux.cc&l=130.
Yup, I was trying to emulate the behavior of a a father process which sends its child one socket to consume, from time to time. >> So the two issues show up when you want to call sendmsg and recvmsg >> with no data at all, but only control messages. sendmsg allocates an >> empty mbuf for data (m_len == 0), this mbuf is not discarded and freed >> by soreceive for SOCK_STREAM sockets, and stays in the socket buffer. >> >> I understand that this API was probably not designed to pass only >> control messages, and no data at all. But it is easily fixable, and the >> manpage could provide portability information. > > Blah, I'm not really a fan of allowing sending zero-length data > messages. It makes it tricky for receivers to tell if they actually > received an EOF or not. For SOCK_DGRAM / SOCK_SEQPACKET, a zero-length message is fine. For SOCK_STREAM, it sounds weird to wake up the listening process when it's going to receive 0 as a return value, indeed. > But if we're going to allow it (which we do currently it seems), then > your diff seems like a reasonable fix to me. mbufs aren't my > specialty though. =/ I'm not saying it's reasonable. If people have a clearer view of the situation than me, I'd be glad to hear it. I lack available brain cells these days... and after all it's not really an issue, just a "funny" corner case. -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE