bufferevent_read_pressure_cb(struct evbuffer *buf, size_t old, size_t now,
void *arg) {
struct bufferevent *bufev = arg;
- /*
- * If we are below the watermark then reschedule reading if it's
- * still enabled.
+ /*
+ * If we are now below the watermark, then we don't need the callback any
+ * more, and we can read again.
*/
if (bufev->wm_read.high == 0 || now < bufev->wm_read.high) {
evbuffer_setcb(buf, NULL, NULL);
{
size_t len;
- bufferevent_add(&bufev->ev_read, bufev->timeout_read);
-
/* nothing user visible changed? */
if (!progress)
return;
what |= EVBUFFER_ERROR;
}
}
-
+
if (res <= 0)
goto error;
return;
reschedule:
- bufferevent_add(&bufev->ev_read, bufev->timeout_read);
return;
error:
+ event_del(&bufev->ev_read);
(*bufev->errorcb)(bufev, what, bufev->cbarg);
+
}
static void
goto error;
}
- if (EVBUFFER_LENGTH(bufev->output) != 0)
- bufferevent_add(&bufev->ev_write, bufev->timeout_write);
+ if (EVBUFFER_LENGTH(bufev->output) == 0)
+ event_del(&bufev->ev_write);
/*
* Invoke the user callback if our buffer is drained or below the
return;
reschedule:
- if (EVBUFFER_LENGTH(bufev->output) != 0)
- bufferevent_add(&bufev->ev_write, bufev->timeout_write);
+ if (EVBUFFER_LENGTH(bufev->output) == 0)
+ event_del(&bufev->ev_write);
return;
error:
+ event_del(&bufev->ev_write);
(*bufev->errorcb)(bufev, what, bufev->cbarg);
}
return (NULL);
}
- event_set(&bufev->ev_read, fd, EV_READ, bufferevent_readcb, bufev);
- event_set(&bufev->ev_write, fd, EV_WRITE, bufferevent_writecb, bufev);
+ event_set(&bufev->ev_read, fd, EV_READ|EV_PERSIST, bufferevent_readcb, bufev);
+ event_set(&bufev->ev_write, fd, EV_WRITE|EV_PERSIST, bufferevent_writecb, bufev);
bufferevent_setcb(bufev, readcb, writecb, errorcb, cbarg);
event_del(&bufev->ev_read);
event_del(&bufev->ev_write);
- event_assign(&bufev->ev_read, bufev->ev_base, fd, EV_READ, bufferevent_readcb, bufev);
- event_assign(&bufev->ev_write, bufev->ev_base, fd, EV_WRITE, bufferevent_writecb, bufev);
+ event_assign(&bufev->ev_read, bufev->ev_base, fd, EV_READ|EV_PERSIST, bufferevent_readcb, bufev);
+ event_assign(&bufev->ev_write, bufev->ev_base, fd, EV_WRITE|EV_PERSIST, bufferevent_writecb, bufev);
/* we need to free all filter contexts and then init them again */
TAILQ_FOREACH(filter, &bufev->input_filters, next) {