From 879d24961973c2dcf6de64a7e0229adcbad484b7 Mon Sep 17 00:00:00 2001 From: yuangongji <82787816@qq.com> Date: Fri, 18 Oct 2019 21:03:40 +0800 Subject: [PATCH] evutil: make evutil_socketpair() have the same behavior on Windows with build number lower and higher than 17063 --- evutil.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/evutil.c b/evutil.c index 582b241a..13631263 100644 --- a/evutil.c +++ b/evutil.c @@ -229,7 +229,7 @@ evutil_check_working_afunix_() * socket(AF_UNIX, , ) and fall back to socket(AF_INET, , ). * https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ */ - int sd = -1; + evutil_socket_t sd = -1; if (have_working_afunix_ < 0) { if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { have_working_afunix_ = 0; @@ -352,13 +352,19 @@ evutil_win_socketpair(int family, int type, int protocol, EVUTIL_SET_SOCKET_ERROR(WSAEAFNOSUPPORT); return -1; } - if (family == AF_UNIX && evutil_check_working_afunix_()) { - /* Win10 does not support AF_UNIX socket of a type other - * than SOCK_STREAM still now. */ - type = SOCK_STREAM; + if (evutil_check_working_afunix_()) { + /* If the AF_UNIX socket works, we will change the family to + * AF_UNIX forcely. */ + family = AF_UNIX; + if (type != SOCK_STREAM) { + /* Win10 does not support AF_UNIX socket of a type other + * than SOCK_STREAM still now. */ + EVUTIL_SET_SOCKET_ERROR(WSAEAFNOSUPPORT); + return -1; + } } else { - /* If the family is set to AF_UNIX and it does not work, - * we will change it to AF_UNIX forcely. */ + /* If the AF_UNIX socket does not work, we will change the + * family to AF_INET forcely. */ family = AF_INET; } if (family == AF_UNIX) -- 2.40.0