[zeromq-dev] [PATCH] ZMQ_PEER_EXISTS option

Artur Brugeman brugeman.artur at gmail.com
Tue Jun 7 10:55:18 CEST 2011


Hi.

I'm offering a patch which allows us to check whether a certain named pipe
exists at XREP socket. Works this way:

char * identity = ...;
size_t len = strlen (identity);
assert (len > 0);
zmq_getsockopt (socket, ZMQ_PEER_EXISTS, identity, &len);

// len is reset to 0 if such peer exists
if (len != 0)
{
 // if peer does not exist, do something, say - connect to it.
 zmq_connect (socket, peer_address);
}

I'm not quite sure about the option name, and an unusual usage of
getsockopt, but the functionality is useful - I haven't found a way to avoid
it.

Consider a p2p application where each peer establishes a link with some set
of other peers. A zmq sockets' ability to bind and connect simultaneously
looks very promising. I create a single XREP socket at each peer, bind it to
accept incoming connections, and connect to establish outgoing connections.
Imagine peers decide to talk to others based on some external conditions.
Say peer A could connect to peer B. Later on, peer B decides to talk to A.
It tries to connect to A. Now, with version 2.1.7 it'll get an assertion
failure, because peer A's socket is connected to B and has a pipe named by
B's identity, and B is trying to connect to A with same identity, and
duplicate identities are not allowed. If I switch to zeromq2-2, things are a
bit better - a new connection is silently rejected by A, with B still being
talk to A (as named pipe already exists). However, B starts reconnecting
after certain intervals, which is, well, a resource waste and is simply
annoying :)

With this patch I managed to check whether a socket can already talk to
certain peer before connecting to that peer.

Hope you get my point and find this patch correct and useful.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110607/005109e3/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ZMQ_PEER_EXISTS-option-added.patch
Type: application/octet-stream
Size: 4134 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110607/005109e3/attachment.obj>


More information about the zeromq-dev mailing list