There are a few reasons I don't like the timeout approach, and don't teach it.
First, it only works when you are working with a single socket and if you want to add a second one, you have to redesign your code, which is a bad way to make code. Second, it's a polling approach (ironically, zmq_poll is actually a more event-driven approach), and leads to poor designs. When you use zmq_poll, your code tends to be clean, and scalable. -Pieter On Fri, Feb 1, 2013 at 1:13 PM, Balázs Varga <[email protected]> wrote: > Hello, > > If somebody want to set a timeout when receiving from a socket, there are > two approaches: > > 1. setting ZMQ_RCVTIMEO socket options and call zmq_recv() which will set > error EAGAIN, if there's nothing in the queue > > and > > 2. polling the socket with a given timeout? > > zmq_pollitem_t items [] = { { socket, 0, ZMQ_POLLIN, 0 } }; > int rc = zmq_poll (items, 1, timeout * ZMQ_POLL_MSEC); > > which will return 0 if nothing to receive. > > In the guide I see that the second method is widely used, however as I > remember I haven't met with the 1st approach. why is this, is it just a > choice, or are there any performance or other differences? > > thx > > b. > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
