[zeromq-dev] adding timeout in zmq_poll

Martin Sustrik sustrik at 250bpm.com
Tue Dec 29 16:55:48 CET 2009

Hi Pavel,

>>> I found discrepancy in zmq_poll manpage. in zmq_pollitem_t section
>>> ZMQ_POLLIN and ZMQ_POLLOUT is discussed, but in example section only
>>> POLLIN is used.
>> The problem is that until watermarks are ported to 0MQ/2.0 you can _always_
>> write to a socket. Thus polling for ZMQ_POLLOUT never blocks at the moment.
> I think that piece of man page with example:
> zmq_pollitem_t items [2];
> items [0].socket = s;
> items [0].events = POLLIN;
> items [1].socket = NULL;
> items [1].fd = my_fd;
> items [1].events = POLLIN;
> should be written as:
> zmq_pollitem_t items [2];
> items [0].socket = s;
> items [0].events = ZMQ_POLLIN;
> items [1].socket = NULL;
> items [1].fd = my_fd;
> items [1].events = POLLIN;

Ok. Got it. Fixed. Thanks.

> Patch for adding timeout to zmq_poll is attached. i added long timeout
> parameter instead unsigned long. In this case developers can specify
> negative value to get commonly used behaviour.

Understood. This get max timout down to something like 40 minutes, but 
that's probably enough.

> I tested patch under linux and it works. Testing programs i attached
> too (they are modified sources of chat example). Running:
> ./display tcp://
> ./prompt tcp:// nickname
> I updated common lisp bindings but i can't check it (i'm not familiar
> with Lisp). May be Vitaly may do this?

> I tried to test code under windows, but without success. I can't
> compile original version of ZMQ2 sources with VS 2008 Express edition
> as described in http://www.zeromq.org/area:download-v20-alpha3#toc10.
> I get errors like:
> x:\temp\_1\zeromq2\src\socket_base.cpp(334) : error C2065:
> 'EINPROGRESS' : undeclared identifier
> x:\temp\_1\zeromq2\src\sub.cpp(147) : error C2065: 'EINPROGRESS' :
> undeclared identifier

Oops. This was introduced by the change I've commited yesterday. Win32 
for some strange reason doesn't define full set of POSIX error codes. 
Anyway, the problem is fixed now.

> But modifications in linux/windows parts of zmq_poll() are similar, i
> hope all will be ok.
> Martin, please review patch and commit it to trunk (under required MIT
> license) if there no warnings.

Thanks. I am leaving for new year celebration in few minutes so I'll 
review the patch when I'll get out of hangover in January.

Cheers and happy new year!

More information about the zeromq-dev mailing list