tags:

views:

89

answers:

1

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?

+2  A: 

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 an IN_DELETE_SELF on it.
  • bind'ing will trigger an IN_CREATE on the parent directory.

Unfortunately, the server isn't connect'able until it listen's. Though this is the next logical step, there's really no guarantee it will do so right away. It doesn't look as though inotify provides an interface to that.

JB
Thanks for the useful suggestion - It's definitely a start. I need to be able to support Solaris as well as Linux, though Solaris seems to have a similar feature called FAM.
James