[zeromq-dev] [PATCH] ZMQ_PEER_EXISTS option
Pieter Hintjens
ph at imatix.com
Tue Jun 7 12:15:46 CEST 2011
Hi Artur,
Just to confirm your use case...
You're using explicit identities for each node, right? Connecting out
from ROUTER to ROUTER, and trying to avoid both incoming and outgoing
connections between the same two nodes?
-Pieter
On Tue, Jun 7, 2011 at 10:55 AM, Artur Brugeman
<brugeman.artur at gmail.com> wrote:
> 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!
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
More information about the zeromq-dev
mailing list