[zeromq-dev] ipc yet again

Martin Sustrik sustrik at 250bpm.com
Thu Jan 7 08:47:25 CET 2010

Hi Jon,

> been off the zmq loop for a day or so
>> In any case I would suggest following the path discussed before: Open a
>> TCP connection, pass a unix domain socket from connecting app to binding
>> app (in form of a generated filename, INET domain sockets are not
>> capable of passing raw sockets AFAIK). Close the TCP socket, use the
>> pipe instead.
> so following erik's suggestion we use AF_LOCAL socket rather than pipe.

Actually, if using AF_LOCAL, the task turns out to be extremely simple. 
Just open AF_LOCAL listening socket in zmq_listener_t and AF_LOCAL 
connecting socket in zmq_connecter_t. The api of both classes can be 
modified as follows:

-        int set_address (const char *addr_);
+        int set_address (const char *transport_, const char *addr_);

That way you can either open a tcp connection:

set_address ("tcp", "");

or an IPC connection:

set_address ("ipc", "/myfile");

Further, connect and bind functions in socket_base_t should be modified 
to accept ipc as well as tcp connections:

- if (addr_type == "tcp") {
+ if (addr_type == "tcp" || addr_type == "ipc") {

Obviously, it won't work on Windows so something like this is needed:

#if defined ZMQ_HAVE_WINDOWS
     return ENOTSUP;

> Then the sequence is approximately
> 1) server starts up and binds a special address which  is actually on 
> localhost:XXXX
> eg
> zmq::socket_t s(ctx, ZMQ_REP);
> s.bind("?????") ; // this actually listens on for example
> how is the port set up determined?
> what is the convention for the ?????

With AF_UNIX sockets there's no need for port number, the address maps 
to a filename:

s.bind ("ipc:///tmp/myfile");

> when a client connects it sends a message which is the path of a UNIX domain 
> socket
> 2) client connections
> 	zmq::socket_t s(ctx, ZMQ_REQ);
> 	s.connect("????"); // a UNIX domain socket is opened, it's path passed as 
> part of the connection protocol. the server opens it's end of the socket, 
> closes tcp loopback and voila.

No need to pass sockets when using AF_LOCAL, no need to close and reopen 
the connection. Everything seems to be much simpler that way.

> should the filename, rather than be generated be set as a socket option?

No need to generate unique names either.

> I may be able to find a bit of spare time, so I could look into this with some 
> assistance.
> where is best to start?

Check zmq_listener_t, zmq_connecter_t and socket_base_t as mentioned 
above. With AF_LOCAL sockets it seems that it won't take more than 2-3 
hours to implement the feature.


More information about the zeromq-dev mailing list