mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 04:50:37 -04:00
be: introduce bufferevent_generic_adj_existing_timeouts_()
And use it in openssl/sock layers to avoid copy-pasting it's variants.
This commit is contained in:
parent
f4b6284b83
commit
3c1f58f58b
@ -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,
|
* 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. */
|
* 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_timeouts_(struct bufferevent *bev);
|
||||||
|
int bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev);
|
||||||
|
|
||||||
enum bufferevent_options bufferevent_get_options_(struct bufferevent *bev);
|
enum bufferevent_options bufferevent_get_options_(struct bufferevent *bev);
|
||||||
|
|
||||||
|
@ -969,6 +969,29 @@ bufferevent_generic_adj_timeouts_(struct bufferevent *bev)
|
|||||||
return 0;
|
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
|
int
|
||||||
bufferevent_add_event_(struct event *ev, const struct timeval *tv)
|
bufferevent_add_event_(struct event *ev, const struct timeval *tv)
|
||||||
{
|
{
|
||||||
|
@ -1254,23 +1254,7 @@ be_openssl_adj_timeouts(struct bufferevent *bev)
|
|||||||
if (bev_ssl->underlying) {
|
if (bev_ssl->underlying) {
|
||||||
return bufferevent_generic_adj_timeouts_(bev);
|
return bufferevent_generic_adj_timeouts_(bev);
|
||||||
} else {
|
} else {
|
||||||
int r1=0, r2=0;
|
return bufferevent_generic_adj_existing_timeouts_(bev);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@
|
|||||||
static int be_socket_enable(struct bufferevent *, short);
|
static int be_socket_enable(struct bufferevent *, short);
|
||||||
static int be_socket_disable(struct bufferevent *, short);
|
static int be_socket_disable(struct bufferevent *, short);
|
||||||
static void be_socket_destruct(struct bufferevent *);
|
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_flush(struct bufferevent *, short, enum bufferevent_flush_mode);
|
||||||
static int be_socket_ctrl(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *);
|
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,
|
be_socket_disable,
|
||||||
NULL, /* unlink */
|
NULL, /* unlink */
|
||||||
be_socket_destruct,
|
be_socket_destruct,
|
||||||
be_socket_adj_timeouts,
|
bufferevent_generic_adj_existing_timeouts_,
|
||||||
be_socket_flush,
|
be_socket_flush,
|
||||||
be_socket_ctrl,
|
be_socket_ctrl,
|
||||||
};
|
};
|
||||||
@ -619,29 +618,6 @@ be_socket_destruct(struct bufferevent *bufev)
|
|||||||
EVUTIL_CLOSESOCKET(fd);
|
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
|
static int
|
||||||
be_socket_flush(struct bufferevent *bev, short iotype,
|
be_socket_flush(struct bufferevent *bev, short iotype,
|
||||||
enum bufferevent_flush_mode mode)
|
enum bufferevent_flush_mode mode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user