[zeromq-dev] zloop with fd support and timer cancelling

Pieter Hintjens ph at imatix.com
Wed May 25 16:54:42 CEST 2011

On Wed, May 25, 2011 at 2:58 PM, Kim Lester <kim at dfusion.com.au> wrote:

> One other way might be to use the timer structure pointer. I was avoiding
> creating an incrementing id because then it would possibly need mutex
> protection unless we are going to guarantee the structure is only used by a
> single thread.

The zloop structure isn't threadsafe, so this is fine. Making
threadsafe data structures is a whole problem in itself... I'm going
to change the API so that timer handlers are passed the timer
reference, rather than an empty pollitem reference. They can then
cancel using that timer reference.

> The zmq_pollitem_t variable can thus be discarded after use, indeed I
> initialise all my sockets with the same pollitem structure, just changing
> the socket ptr between calls.


> Since most programs only need the socket/fd they won't keep the pollitem_t
> structure around so to cancel a socket we then need to create a new 0 filled
> z_pollitem_t and set the socket/fd in it. A very minor point.

In most cases the handler will cancel itself, so just passes the
pollitem it received.

> One alternative that might be acceptable - since zsocket_new and
> zsocket_type etc already exist as partial wrappers around the underlying zmq
> library, you might be able to add new socket types here...

The zsocket class uses native 0MQ sockets (to allow apps to use the
native API for all socket work including message I/O). I'd hesitate to
invent a new socket type layer on top of that, it'd make the semantics
quite messy.

Anyhow, no need, we can just pass opaque timer references to handlers.
If we decide we need to cancel timers on some other basis, i.e. from
other handlers, we can use timer names of some kind.


More information about the zeromq-dev mailing list