libevent
libevent copied to clipboard
bufferevent_replacefd close socket when bufferevent‘s socket fd is eq new fd
in function int bufferevent_replacefd(struct bufferevent *bev, evutil_socket_t fd)
line 896 only check if (old_fd != EVUTIL_INVALID_SOCKET)
but not check fd is eq old_fd
Thanks for the report.
The check for old_fd is done to check should be call close or not, for new fd we do not need this. Are you experiencing some issues with this behavior?
I first exported evhttp_get_request as a public function for logical processing.
After accepting a socket, use bufferevent to read the handshake information, then determine the protocol type, if it is http protocol, it is processed by evhttp_get_request. This is done by passing the bufferevent and socket fd into evhttp_get_request, however, in the processing of evhttp_get_request, the bufferevent_replacefd function will be called, and at this time, the fd of the bufferevent and the fd of the socket are equal,. bufferevent_replacefd does not determine whether the new fd and old fd are equal, but instead closes the old fd directly, causing the socket to be closed.
I first exported evhttp_get_request as a public function for logical processing.
This is not an official API Thought it had been requested multiple times - https://github.com/libevent/libevent/issues/1471 Are you interested? I'm OK with exporting it if it will have some example that will show that it make sense in the official repo
but not check fd is eq old_fd
And then I'm ok with this change as well