[zeromq-dev] Best way to punt on a ZMQ_REQ?

Martin Sustrik sustrik at 250bpm.com
Fri Jun 11 07:41:38 CEST 2010


Matt,

> I'm using a ZMQ_REQ socket to send a query to a server, and I need to  
> timeout if the response isn't received on time.
> 
> The best way would seem to be to zmq::poll with a timeout (not working  
> for me at present, see my prior email).  Alternatively I could use  
> ZMQ_NOBLOCK and a sleep loop, but that's ugly.
> 
> In any event, after I go away I'm left with a socket that's in the  
> wrong state for the next request, which may arrive before the last  
> request.  I don't see any way of resetting a socket, so I'm presuming  
> my best bet is to tear down the socket and use a new one for the next  
> request?

Unfortunately yes, the socket must be torn down.

> Meanwhile, what happens to the server at the other end of the request,  
> still holding pieces of state through a zmq::queue via a ZMQ_XREP  
> socket?

The old reply may still arrive. What's needed is to tag the request, 
copy the tag to the reply and check the reply whether it contains the 
same tag. If it does now, it's a stale reply and it should be discarded.

All this is going to be added to 0MQ in next couple of weeks/months.

You can either wait for the patch, implement the behaviour on top of 0MQ 
or help with the 0MQ patch yourself.

(implementing on top of 0MQ seems like a waste of effort to me btw)

Martin



More information about the zeromq-dev mailing list