I am writing a client app which connects to a server process through a Unix domain socket. If the server process is not running, I want the client to wait until the server has started and is listening for connections on the socket.
Currently I have a retry loop in the client which calls connect() every second until it successfully connects to the socket.
Is there any function I can call which will simply block until a particular named socket (e.g. "/var/mysock") is created and bound to a server process?
Best Answer
Not a full answer, but...
If you're on Linux, the
inotify
interface will let you trap a the first few useful steps of the operation:unlink
'ing a leftover former socket will trigger anIN_DELETE_SELF
on it.bind
'ing will trigger anIN_CREATE
on the parent directory.Unfortunately, the server isn't
connect
'able until itlisten
's. Though this is the next logical step, there's really no guarantee it will do so right away. It doesn't look as thoughinotify
provides an interface to that.