[nanomsg] Re: Help with an IPC problem!

  • From: Paul Colomiets <paul@xxxxxxxxxxxxxx>
  • To: "nanomsg@xxxxxxxxxxxxx" <nanomsg@xxxxxxxxxxxxx>
  • Date: Thu, 6 Nov 2014 20:52:32 +0200

Hi Martin,

On Thu, Nov 6, 2014 at 8:42 PM, Martin Sustrik <sustrik@xxxxxxxxxx> wrote:
> What would help is testing (in nn_bind) whether the IPC file is
> actually used by anybody and if not so, deleting it.

The common pattern is in process doing bind to something like this (pseudocode):

if not bind(s, xx) {
  y = socket(...)
  if connect(y, xx) {
    raise "Address already in use"
  }
  close(y);
}
unlink(xx)
if not bind(s, xx) {
    raise "Race condition: Address already in use"
}

I.e. check if you can connect to socket, then it's used. Note,
hovewer, I'm not sure what happens if old process hangs not doing
"accept()". Probably result EINPROGRESS for "connect()" should be
considered successful.

-- 
Paul

Other related posts: