diff options
author | Azat Khuzhin <a3at.mail@gmail.com> | 2018-11-11 21:35:20 +0300 |
---|---|---|
committer | Azat Khuzhin <a3at.mail@gmail.com> | 2018-11-13 22:29:08 +0300 |
commit | a54c0349119cde9a000ebb84840c4a4d7ed3d726 (patch) | |
tree | 00bb32d376149e5874d7392d93f2ccda46050ea1 /bufferevent_async.c | |
parent | 5dc88b387f7baa4bcd528832e94987a85be3b263 (diff) | |
download | libevent-a54c0349119cde9a000ebb84840c4a4d7ed3d726.tar.gz |
bev_async: ignore ERROR_INVALID_PARAMETER on .setfd for iocp
listener already calls event_iocp_port_associate_() the second call will
return ERROR_INVALID_PARAMETER.
Plus we already ignore it on creation, so why we should care about it
here?
Diffstat (limited to 'bufferevent_async.c')
-rw-r--r-- | bufferevent_async.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/bufferevent_async.c b/bufferevent_async.c index 1521d896..3f06341f 100644 --- a/bufferevent_async.c +++ b/bufferevent_async.c @@ -100,6 +100,19 @@ const struct bufferevent_ops bufferevent_ops_async = { be_async_ctrl, }; +static inline int +fatal_error(int err) +{ + switch (err) { + /* We may have already associated this fd with a port. + * Let's hope it's this port, and that the error code + * for doing this neer changes. */ + case ERROR_INVALID_PARAMETER: + return 0; + } + return 1; +} + static inline struct bufferevent_async * upcast(struct bufferevent *bev) { @@ -532,11 +545,7 @@ bufferevent_async_new_(struct event_base *base, return NULL; if (fd >= 0 && event_iocp_port_associate_(iocp, fd, 1)<0) { - int err = GetLastError(); - /* We may have alrady associated this fd with a port. - * Let's hope it's this port, and that the error code - * for doing this neer changes. */ - if (err != ERROR_INVALID_PARAMETER) + if (fatal_error(GetLastError())) return NULL; } @@ -660,8 +669,10 @@ be_async_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, return 0; if (!(iocp = event_base_get_iocp_(bev->ev_base))) return -1; - if (event_iocp_port_associate_(iocp, data->fd, 1) < 0) - return -1; + if (event_iocp_port_associate_(iocp, data->fd, 1) < 0) { + if (fatal_error(GetLastError())) + return -1; + } evbuffer_overlapped_set_fd_(bev->input, data->fd); evbuffer_overlapped_set_fd_(bev->output, data->fd); return 0; |