[zeromq-dev] czmq / zloop / zmq_poll / timers
Kim Lester
kim at dfusion.com.au
Mon May 23 19:45:01 CEST 2011
I was about to write a timer system when I came across zloop (thanks!)
In some of my use-cases there appears to be a problem however that I wanted to discuss.
One of my connections is a fd not a zmq socket (recall zmq_pollitem_t can handle both).
This would however mean amending zloop_reader to handle fd's OR a new function.
I suspect my preference would be to pass in a zmq_pollitem_t to the reader which would also impact zloop_start() a little and handle POLLOUT automagically I think.
I'd also like to suggest that rather than passing void *socket to the handler that it passes zmq_pollitem_t *, not only does
this solve my problem :-) of passing an fd to the handler but it also allows the handler to check r_events easily.
I'm no expert on zmq, but I presume that one might want to check for POLLERR and POLLOUT as well one day and distinguish them in the handler.
So the handler would need to be (*handler)(zloop_t *zloop, zmq_pollitem_t *item, void *arg);
I don't mind sending patches but I'm still new to zmq so I may miss some subtlety in zmq_poll processing and I may end up implementing the following option anyway:
Another option for timers (if one is using threads anyway) is to create a timer thread which can then send "tickless" events via a zmq socket to any other interested threads (without too much IPC delay hopefully). I may go down this path as it allows one to potentially add new timers at a shorter interval than the current timeout.
The current reactor cannot AFAIK be interrupted nicely (I suppose I could send a signal :-( ) whereas by the very fact of having a socket that can receives "timer update" events (as well as timer expired events) means that the current timeout is interrupted by a POLLIN event and this can trigger timer set recalculations (additions/deletions etc)
Any comments on that from the zmq brains trust ?
As an aside IMHO it would be great if zmq_poll integrated timers like into zmq (rather like the linux specific timerfd_create()).
because timers are so common/useful even if not strictly comms related.
regards
Kim
More information about the zeromq-dev
mailing list