Skip to content
Browse files

zloop_poller: control disabling of event handler on POLLERR

Normally a POLLERR flag returned from poll(2) will disable the
event handler after the first callback. For some file types,
POLLERR is not an error situation and this behaviour is
undesirable. To keep the handler enabled despite POLLERR being
returned, define the pollitem like so:

zmq_pollitem_t items [] = {
       { 0, fd, ZMQ_IGNERR|ZMQ_POLLIN, 0 }
};
  • Loading branch information...
1 parent 5b11e83 commit 09e37111ea0e289962968c72597c6adcad606357 Michael Haberler committed Sep 26, 2012
Showing with 10 additions and 1 deletion.
  1. +6 −0 include/zloop.h
  2. +4 −1 src/zloop.c
View
6 include/zloop.h
@@ -31,6 +31,7 @@
extern "C" {
#endif
+
// Opaque class structure
typedef struct _zloop_t zloop_t;
@@ -86,6 +87,11 @@ int
zloop_test (Bool verbose);
// @end
+
+// to suppress disabling the event handler on POLLERR
+// set this in pollitem.events
+#define ZMQ_IGNERR 8
+
#ifdef __cplusplus
}
#endif
View
5 src/zloop.c
@@ -63,6 +63,7 @@ struct _s_poller_t {
zmq_pollitem_t item;
zloop_fn *handler;
void *arg;
+ Bool ignore_errors;
int errors; // If too many errors, kill poller
};
@@ -79,6 +80,7 @@ s_poller_new (zmq_pollitem_t *item, zloop_fn handler, void *arg)
{
s_poller_t *poller = (s_poller_t *) zmalloc (sizeof (s_poller_t));
if (poller) {
+ poller->ignore_errors = (item->events & ZMQ_IGNERR);
poller->item = *item;
poller->handler = handler;
poller->arg = arg;
@@ -389,7 +391,8 @@ zloop_start (zloop_t *self)
for (item_nbr = 0; item_nbr < self->poll_size; item_nbr++) {
s_poller_t *poller = &self->pollact [item_nbr];
assert (self->pollset [item_nbr].socket == poller->item.socket);
- if (self->pollset [item_nbr].revents & ZMQ_POLLERR) {
+ if ((self->pollset [item_nbr].revents & ZMQ_POLLERR) &&
+ !poller->ignore_errors) {
if (self->verbose)
zclock_log ("I: zloop: can't poll %s socket (%p, %d): %s",
poller->item.socket?

0 comments on commit 09e3711

Please sign in to comment.
Something went wrong with that request. Please try again.