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