[zeromq-dev] ZMQ_EVENTS not working correctly with ZMQ_ROUTER_MANDATORY
Luca Boccassi
luca.boccassi at gmail.com
Tue Jun 6 15:54:43 CEST 2017
On Tue, 2017-06-06 at 10:09 +0200, Radek Svoboda wrote:
> Following pseudocode fails on asserts, although it should not:
>
> zmq::socket_t router(ctx,ZMQ_ROUTER);
> router.setsockopt(ZMQ_SNDHWM,10);
> router.setsockopt(ZMQ_ROUTER_MANDATORY,1);
> router.bind("inproc://test");
> while(publish.getsockopt<int>(ZMQ_EVENTS) & ZMQ_POLLOUT)
> {
> assert(s_sendmore(router,"DEALERID",ZMQ_DONTWAIT));
> assert(s_sendmore(router,"",ZMQ_DONTWAIT));
> assert(s_send(router,"HELLO",ZMQ_DONTWAIT));
> }
> The problem is that getsockopt() signals free slot for message to be
> sent,
> but it is not. Is this behavior a bug or undocumented feature of
> ZMQ_ROUTER_MANDATORY?
>
> Thank you
> Radek Svoboda
That's because it depends on where the message it's being sent to.
The getsockopt format for ZMQ_EVENTS does not allow for that
information to be passed down.
This inline comment can be seen for the ZMQ_ROUTER xhas_out
implementation:
"In theory, ROUTER socket is always ready for writing. Whether actual
attempt to write succeeds depends on which pipe the message is going to
be routed to."
The solution is not to just assert when using ZMQ_ROUTER_MANDATORY.
As its documentation says, if the requested recipient is not available
-1 will be returned and errno will be set to EHOSTUNREACH (or EAGAIN if
the HWM is full). You should check for this and react accordingly.
Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170606/28c88263/attachment.sig>
More information about the zeromq-dev
mailing list