Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZeroMQ: Check if someone is listening behind Unix domain socket

Context: Linux (Ubuntu), C, ZeroMQ

I have a server which listens on ipc:// SUB ZeroMQ socket (which physically is a Unix domain socket).

I have a client which should connect to the socket, publish its message and disconnect.

The problem: If server is killed (or otherwise dies unnaturally), socket file stays in place. If client attempts to connect to this stale socket, it blocks in zmq_term().

I need to prevent client from blocking if server is not there, but guarantee delivery if server is alive but busy.

Assume that I can not track server lifetime by some external magic (e.g. by checking a PID file).

Any hints?

like image 289
Alexander Gladysh Avatar asked Apr 23 '11 18:04

Alexander Gladysh


1 Answers

Non-portable solution seems to be to read /proc/net/unix and search there for a socket name.

like image 98
Alexander Gladysh Avatar answered Sep 27 '22 23:09

Alexander Gladysh