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 SvobodaThat'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
signature.asc
Description: This is a digitally signed message part
_______________________________________________ zeromq-dev mailing list [email protected] https://lists.zeromq.org/mailman/listinfo/zeromq-dev
