static int be_async_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, union bufferevent_ctrl_data *data) { switch (op) { case BEV_CTRL_GET_FD: data->fd = _evbuffer_overlapped_get_fd(bev->input); return 0; case BEV_CTRL_SET_FD: { struct event_iocp_port *iocp; if (data->fd == _evbuffer_overlapped_get_fd(bev->input)) 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; _evbuffer_overlapped_set_fd(bev->input, data->fd); _evbuffer_overlapped_set_fd(bev->output, data->fd); return 0; } case BEV_CTRL_GET_UNDERLYING: default: return -1; } }
static int be_async_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, union bufferevent_ctrl_data *data) { switch (op) { case BEV_CTRL_GET_FD: data->fd = _evbuffer_overlapped_get_fd(bev->input); return 0; case BEV_CTRL_SET_FD: { struct event_iocp_port *iocp; if (data->fd == _evbuffer_overlapped_get_fd(bev->input)) 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; _evbuffer_overlapped_set_fd(bev->input, data->fd); _evbuffer_overlapped_set_fd(bev->output, data->fd); return 0; } case BEV_CTRL_CANCEL_ALL: { struct bufferevent_async *bev_a = upcast(bev); evutil_socket_t fd = _evbuffer_overlapped_get_fd(bev->input); if (fd != (evutil_socket_t)INVALID_SOCKET && (bev_a->bev.options & BEV_OPT_CLOSE_ON_FREE)) { closesocket(fd); } bev_a->ok = 0; return 0; } case BEV_CTRL_GET_UNDERLYING: default: return -1; } }