diff --git a/bufferevent-internal.h b/bufferevent-internal.h index c84f09c0..d9d9e666 100644 --- a/bufferevent-internal.h +++ b/bufferevent-internal.h @@ -412,6 +412,7 @@ void bufferevent_init_generic_timeout_cbs_(struct bufferevent *bev); * we delete it.) Call this from anything that changes the timeout values, * that enabled EV_READ or EV_WRITE, or that disables EV_READ or EV_WRITE. */ int bufferevent_generic_adj_timeouts_(struct bufferevent *bev); +int bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev); enum bufferevent_options bufferevent_get_options_(struct bufferevent *bev); diff --git a/bufferevent.c b/bufferevent.c index a1fa6227..59ae24f1 100644 --- a/bufferevent.c +++ b/bufferevent.c @@ -969,6 +969,29 @@ bufferevent_generic_adj_timeouts_(struct bufferevent *bev) return 0; } +int +bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev) +{ + int r = 0; + if (event_pending(&bev->ev_read, EV_READ, NULL)) { + if (evutil_timerisset(&bev->timeout_read)) { + if (bufferevent_add_event_(&bev->ev_read, &bev->timeout_read) < 0) + r = -1; + } else { + event_remove_timer(&bev->ev_read); + } + } + if (event_pending(&bev->ev_write, EV_WRITE, NULL)) { + if (evutil_timerisset(&bev->timeout_write)) { + if (bufferevent_add_event_(&bev->ev_write, &bev->timeout_write) < 0) + r = -1; + } else { + event_remove_timer(&bev->ev_write); + } + } + return r; +} + int bufferevent_add_event_(struct event *ev, const struct timeval *tv) { diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c index 7d469bfa..54b72197 100644 --- a/bufferevent_openssl.c +++ b/bufferevent_openssl.c @@ -1254,23 +1254,7 @@ be_openssl_adj_timeouts(struct bufferevent *bev) if (bev_ssl->underlying) { return bufferevent_generic_adj_timeouts_(bev); } else { - int r1=0, r2=0; - if (event_pending(&bev->ev_read, EV_READ, NULL)) { - if (evutil_timerisset(&bev->timeout_read)) { - r1 = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); - } else { - event_remove_timer(&bev->ev_read); - } - } - if (event_pending(&bev->ev_write, EV_WRITE, NULL)) { - if (evutil_timerisset(&bev->timeout_write)) { - r2 = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); - } else { - event_remove_timer(&bev->ev_write); - } - } - - return (r1<0 || r2<0) ? -1 : 0; + return bufferevent_generic_adj_existing_timeouts_(bev); } } diff --git a/bufferevent_sock.c b/bufferevent_sock.c index ffc6c772..431d6e4b 100644 --- a/bufferevent_sock.c +++ b/bufferevent_sock.c @@ -79,7 +79,6 @@ static int be_socket_enable(struct bufferevent *, short); static int be_socket_disable(struct bufferevent *, short); static void be_socket_destruct(struct bufferevent *); -static int be_socket_adj_timeouts(struct bufferevent *); static int be_socket_flush(struct bufferevent *, short, enum bufferevent_flush_mode); static int be_socket_ctrl(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *); @@ -92,7 +91,7 @@ const struct bufferevent_ops bufferevent_ops_socket = { be_socket_disable, NULL, /* unlink */ be_socket_destruct, - be_socket_adj_timeouts, + bufferevent_generic_adj_existing_timeouts_, be_socket_flush, be_socket_ctrl, }; @@ -619,29 +618,6 @@ be_socket_destruct(struct bufferevent *bufev) EVUTIL_CLOSESOCKET(fd); } -static int -be_socket_adj_timeouts(struct bufferevent *bufev) -{ - int r = 0; - if (event_pending(&bufev->ev_read, EV_READ, NULL)) { - if (evutil_timerisset(&bufev->timeout_read)) { - if (be_socket_add(&bufev->ev_read, &bufev->timeout_read) < 0) - r = -1; - } else { - event_remove_timer(&bufev->ev_read); - } - } - if (event_pending(&bufev->ev_write, EV_WRITE, NULL)) { - if (evutil_timerisset(&bufev->timeout_write)) { - if (be_socket_add(&bufev->ev_write, &bufev->timeout_write) < 0) - r = -1; - } else { - event_remove_timer(&bufev->ev_write); - } - } - return r; -} - static int be_socket_flush(struct bufferevent *bev, short iotype, enum bufferevent_flush_mode mode)