zirias@
Developer
For a service that can optionally listen on a local (Unix) socket, I want to implement detection of a "stale" socket, so it can startup without user intervention in this case by just unlinking the stale socket. As my service is designed around an event loop using pselect(2), I put all sockets into
In my current design, listening sockets are set up before starting the event loop. Now, to "probe" a local socket for being still active, I need to connect(2) to it. My observation on both Linux and FreeBSD is that, regardless of
What I'm asking here is the following: Is my understanding correct that, if there is no listener on a local socket, POSIX would allow connect(2) to set
O_NONBLOCK
mode, so my main thread is never blocked anywhere other than the central pselect(2) call.In my current design, listening sockets are set up before starting the event loop. Now, to "probe" a local socket for being still active, I need to connect(2) to it. My observation on both Linux and FreeBSD is that, regardless of
O_NONBLOCK
mode, this connect(2) returns an error (other than EINPROGRESS
) immediately if there is no listener on the local socket. This is perfect for my usecase, as I don't need any special handling -- if the connect(2) succeeds (with my logic that doesn't treat EINPROGRESS
as an error, but just sets a "connecting" flag), I know the socket is still active.What I'm asking here is the following: Is my understanding correct that, if there is no listener on a local socket, POSIX would allow connect(2) to set
EINPROGRESS
and report the error later via SO_ERROR
? And if so, are there systems behaving that way?