title: Detecting connection close on AF_UNIX, SOCK_SEQPACKET socket without using poll
body: <p>For a bound and connected (to an <em>unbound</em> peer) socket created using <code>socket(AF_UNIX, SOCK_SEQPACKET, 0)</code>, is there a way to detect that the remote end has hung up, without using <code>poll</code> (the <code>POLLHUP</code> flag will be set), <code>select</code> (for some reason, appearing in the write fd set), or the like?</p>
  
  <p>Unlike <code>SOCK_STREAM</code>, 0-length payloads are valid and indistinguishable from the end of the stream (as far as I can tell; I keep getting 0-length chunks when calling <code>recvmsg</code> on a socket for which the remote end has called <code>shutdown</code> or <code>close</code>). Also there aren't any known (to me) flags visible in <code>struct msghdr</code> that signal the end of the connection. The only thing I see in the Linux kernel source (<code>net/unix/af_unix.c:unix_seqpacket_recvmsg</code>) is the kernel returning <code>-ENOTCONN</code> presumably if the socket is not connected, and then performing the same work as for <code>SOCK_DGRAM</code>.</p>
  
  <p>Note that it is important to use <code>recvmsg</code> rather than <code>recv</code>, <code>recvfrom</code>, etc, because I need to check the flags for <code>MSG_TRUNC</code>.</p>