mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 04:19:10 -04:00
be_openssl: use bufferevent_enable() instead of bufferevent_add_event_()
By using bufferevent_enable() there will be no event for READ *or* WRITE if they are not enabled before, and this patch reduces difference for be_sock_enable/be_openssl_enable (handshake)
This commit is contained in:
parent
fad5fe2cc1
commit
0c66d3210c
@ -1090,7 +1090,6 @@ set_handshake_callbacks(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd)
|
||||
return do_handshake(bev_ssl);
|
||||
} else {
|
||||
struct bufferevent *bev = &bev_ssl->bev.bev;
|
||||
int r1=0, r2=0;
|
||||
|
||||
if (event_initialized(&bev->ev_read)) {
|
||||
event_del(&bev->ev_read);
|
||||
@ -1103,11 +1102,9 @@ set_handshake_callbacks(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd)
|
||||
event_assign(&bev->ev_write, bev->ev_base, fd,
|
||||
EV_WRITE|EV_PERSIST|EV_FINALIZE,
|
||||
be_openssl_handshakeeventcb, bev_ssl);
|
||||
if (fd >= 0) {
|
||||
r1 = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read);
|
||||
r2 = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write);
|
||||
}
|
||||
return (r1<0 || r2<0) ? -1 : 0;
|
||||
if (fd >= 0)
|
||||
bufferevent_enable(bev, bev->enabled);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1159,9 +1156,6 @@ be_openssl_enable(struct bufferevent *bev, short events)
|
||||
struct bufferevent_openssl *bev_ssl = upcast(bev);
|
||||
int r1 = 0, r2 = 0;
|
||||
|
||||
if (bev_ssl->state != BUFFEREVENT_SSL_OPEN)
|
||||
return 0;
|
||||
|
||||
if (events & EV_READ)
|
||||
r1 = start_reading(bev_ssl);
|
||||
if (events & EV_WRITE)
|
||||
|
@ -573,14 +573,12 @@ bufferevent_new(evutil_socket_t fd,
|
||||
static int
|
||||
be_socket_enable(struct bufferevent *bufev, short event)
|
||||
{
|
||||
if (event & EV_READ) {
|
||||
if (bufferevent_add_event_(&bufev->ev_read, &bufev->timeout_read) == -1)
|
||||
if (event & EV_READ &&
|
||||
bufferevent_add_event_(&bufev->ev_read, &bufev->timeout_read) == -1)
|
||||
return -1;
|
||||
}
|
||||
if (event & EV_WRITE) {
|
||||
if (bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1)
|
||||
if (event & EV_WRITE &&
|
||||
bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user