From 85a0ec9b2dcbfdb2c4ea95fc8a8f79e60a46ea62 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 6 May 2024 08:50:36 +0200 Subject: [PATCH] be: make the code in bufferevent_socket_connect() more reliable There is one icky in case for windows: if (sa) { #ifdef _WIN32 if (bufferevent_async_can_connect_(bev)) { bufferevent_setfd(bev, fd); r = bufferevent_async_connect_(bev, fd, sa, socklen); if (r < 0) goto freesock; bufev_p->connecting = 1; result = 0; goto done; - } else + } else { #endif r = evutil_socket_connect_(&fd, sa, socklen); if (r < 0) // Previosly this line was executed // regardless of bufferevent_async_can_connect_(), but the case under // bufferevent_async_can_connect_() always does goto, so it is 100% the // same code, but just to make it more cleaner goto freesock; +#ifdef _WIN32 + } +#endif } --- bufferevent_sock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bufferevent_sock.c b/bufferevent_sock.c index 87d12037..5cda691a 100644 --- a/bufferevent_sock.c +++ b/bufferevent_sock.c @@ -411,11 +411,14 @@ bufferevent_socket_connect(struct bufferevent *bev, bufev_p->connecting = 1; result = 0; goto done; - } else + } else { #endif r = evutil_socket_connect_(&fd, sa, socklen); if (r < 0) goto freesock; +#ifdef _WIN32 + } +#endif } #ifdef _WIN32 /* ConnectEx() isn't always around, even when IOCP is enabled.