From 48773405dd0468ce8a5dca921f0df0360acb80bc Mon Sep 17 00:00:00 2001 From: prettyboy Date: Thu, 14 Feb 2019 20:57:35 +0300 Subject: [PATCH 01/12] Pass WSA_FLAG_NO_HANDLE_INHERIT flags to the WSASocketA() to avoid handle leaking on the Windows in case of using CreateProcess() on the server --- src/core/lib/iomgr/tcp_server_windows.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index b01afdcc9db..67e4f33d44d 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -255,7 +255,7 @@ static grpc_error* start_accept_locked(grpc_tcp_listener* port) { } sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED); + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; @@ -493,7 +493,7 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s, } sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED); + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto done; From 76e9d1add7555378c204eb0475e9b4ac1c8f2816 Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Thu, 21 Feb 2019 19:20:34 +0300 Subject: [PATCH 02/12] Set WSA_FLAG_NO_HANDLE_INHERIT flag wherever the WSASocket is used. Check WSA_FLAG_NO_HANDLE_INHERIT is supported. --- .../dns/c_ares/grpc_ares_ev_driver_windows.cc | 2 +- src/core/lib/iomgr/endpoint_pair_windows.cc | 8 +++---- src/core/lib/iomgr/socket_windows.cc | 21 +++++++++++++++++++ src/core/lib/iomgr/socket_windows.h | 9 ++++++++ src/core/lib/iomgr/tcp_client_windows.cc | 4 ++-- src/core/lib/iomgr/tcp_server_windows.cc | 4 ++-- test/cpp/naming/resolver_component_test.cc | 4 ++-- 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc index 02121aa0ab4..dedc77aae97 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -442,7 +442,7 @@ class SockToPolledFdMap { */ static ares_socket_t Socket(int af, int type, int protocol, void* user_data) { SockToPolledFdMap* map = static_cast(user_data); - SOCKET s = WSASocket(af, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED); + SOCKET s = grpc_create_wsa_socket(af, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (s == INVALID_SOCKET) { return s; } diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index 177331d6812..842a4ff877b 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -40,8 +40,8 @@ static void create_sockets(SOCKET sv[2]) { SOCKADDR_IN addr; int addr_len = sizeof(addr); - lst_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED); + lst_sock = grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); GPR_ASSERT(lst_sock != INVALID_SOCKET); memset(&addr, 0, sizeof(addr)); @@ -53,8 +53,8 @@ static void create_sockets(SOCKET sv[2]) { GPR_ASSERT(getsockname(lst_sock, (grpc_sockaddr*)&addr, &addr_len) != SOCKET_ERROR); - cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED); + cli_sock = grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); GPR_ASSERT(cli_sock != INVALID_SOCKET); GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 999c6646ad4..19013c76b3e 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -181,4 +181,25 @@ int grpc_ipv6_loopback_available(void) { return g_ipv6_loopback_available; } +SOCKET grpc_create_wsa_socket(int family, + int type, + int protocol, + LPWSAPROTOCOL_INFOA protocol_info, + GROUP group, + DWORD flags) { + bool is_wsa_no_handle_inherit_set = flags & WSA_FLAG_NO_HANDLE_INHERIT; + if (!g_is_wsa_no_handle_inherit_supported && is_wsa_no_handle_inherit_set) { + flags ^= WSA_FLAG_NO_HANDLE_INHERIT; + } + SOCKET sock = WSASocket(family, type, protocol, protocol_info, group, flags); + /* WSA_FLAG_NO_HANDLE_INHERIT may be not supported on the older Windows versions, see + https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx + for details. */ + if (sock == INVALID_SOCKET && is_wsa_no_handle_inherit_set) { + g_is_wsa_no_handle_inherit_supported = false; + sock = WSASocket(family, type, protocol, protocol_info, group, flags ^ WSA_FLAG_NO_HANDLE_INHERIT); + } + return sock; +} + #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 46d7d583560..0eb8a2271f5 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -114,6 +114,15 @@ void grpc_socket_become_ready(grpc_winsocket* winsocket, The value is probed once, and cached for the life of the process. */ int grpc_ipv6_loopback_available(void); +static bool g_is_wsa_no_handle_inherit_supported = true; + +SOCKET grpc_create_wsa_socket(int family, + int type, + int protocol, + LPWSAPROTOCOL_INFOA protocol_info, + GROUP group, + DWORD flags); + #endif #endif /* GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H */ diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index e5b5502597e..881f7670610 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -147,8 +147,8 @@ static void tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint, addr = &addr6_v4mapped; } - sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED); + sock = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 67e4f33d44d..9c398ebc8a5 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -254,7 +254,7 @@ static grpc_error* start_accept_locked(grpc_tcp_listener* port) { return GRPC_ERROR_NONE; } - sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + sock = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); @@ -492,7 +492,7 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s, addr = &wildcard; } - sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + sock = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 9532529e45d..072504f4e38 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -279,8 +279,8 @@ void OpenAndCloseSocketsStressLoop(int dummy_port, gpr_event* done_ev) { } std::vector sockets; for (size_t i = 0; i < 50; i++) { - SOCKET s = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, - WSA_FLAG_OVERLAPPED); + SOCKET s = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); ASSERT_TRUE(s != BAD_SOCKET_RETURN_VAL) << "Failed to create TCP ipv6 socket"; gpr_log(GPR_DEBUG, "Opened socket: %d", s); From 39f562e2b78c4b0dfc68f4f7aadafcc0d20b76dd Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Thu, 21 Feb 2019 19:27:09 +0300 Subject: [PATCH 03/12] Define WSA_FLAG_NO_HANDLE_INHERIT if it's not defined --- src/core/lib/iomgr/socket_windows.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 0eb8a2271f5..25b347d1efa 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -32,6 +32,10 @@ #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/iomgr_internal.h" +#ifndef WSA_FLAG_NO_HANDLE_INHERIT +#define WSA_FLAG_NO_HANDLE_INHERIT 0x80 +#endif + /* This holds the data for an outstanding read or write on a socket. The mutex to protect the concurrent access to that data is the one inside the winsocket wrapper. */ From b74044a67d2e4f911cc68395eeadf1c5f6b013fc Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Thu, 21 Feb 2019 19:47:38 +0300 Subject: [PATCH 04/12] Use LPWSAPROTOCOL_INFO instead of LPWSAPROTOCOL_INFOA --- src/core/lib/iomgr/socket_windows.cc | 2 +- src/core/lib/iomgr/socket_windows.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 19013c76b3e..7b0f43bb170 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -184,7 +184,7 @@ int grpc_ipv6_loopback_available(void) { SOCKET grpc_create_wsa_socket(int family, int type, int protocol, - LPWSAPROTOCOL_INFOA protocol_info, + LPWSAPROTOCOL_INFO protocol_info, GROUP group, DWORD flags) { bool is_wsa_no_handle_inherit_set = flags & WSA_FLAG_NO_HANDLE_INHERIT; diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 25b347d1efa..987325eef71 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -123,7 +123,7 @@ static bool g_is_wsa_no_handle_inherit_supported = true; SOCKET grpc_create_wsa_socket(int family, int type, int protocol, - LPWSAPROTOCOL_INFOA protocol_info, + LPWSAPROTOCOL_INFO protocol_info, GROUP group, DWORD flags); From bc7203e37156410b8cf2341013a36fc3f33c5ee7 Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Mon, 25 Feb 2019 12:19:41 +0300 Subject: [PATCH 05/12] Fixed style --- .../dns/c_ares/grpc_ares_ev_driver_windows.cc | 4 +++- src/core/lib/iomgr/endpoint_pair_windows.cc | 10 ++++++---- src/core/lib/iomgr/socket_windows.cc | 13 ++++++------- src/core/lib/iomgr/socket_windows.h | 7 ++----- src/core/lib/iomgr/tcp_client_windows.cc | 5 +++-- src/core/lib/iomgr/tcp_server_windows.cc | 10 ++++++---- test/cpp/naming/resolver_component_test.cc | 5 +++-- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc index dedc77aae97..5d77fb761f3 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -442,7 +442,9 @@ class SockToPolledFdMap { */ static ares_socket_t Socket(int af, int type, int protocol, void* user_data) { SockToPolledFdMap* map = static_cast(user_data); - SOCKET s = grpc_create_wsa_socket(af, type, protocol, nullptr, 0, WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + SOCKET s = grpc_create_wsa_socket( + af, type, protocol, nullptr, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (s == INVALID_SOCKET) { return s; } diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index 842a4ff877b..b914e1c6660 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -40,8 +40,9 @@ static void create_sockets(SOCKET sv[2]) { SOCKADDR_IN addr; int addr_len = sizeof(addr); - lst_sock = grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + lst_sock = + grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); GPR_ASSERT(lst_sock != INVALID_SOCKET); memset(&addr, 0, sizeof(addr)); @@ -53,8 +54,9 @@ static void create_sockets(SOCKET sv[2]) { GPR_ASSERT(getsockname(lst_sock, (grpc_sockaddr*)&addr, &addr_len) != SOCKET_ERROR); - cli_sock = grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + cli_sock = + grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); GPR_ASSERT(cli_sock != INVALID_SOCKET); GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 7b0f43bb170..f55fe674f15 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -181,23 +181,22 @@ int grpc_ipv6_loopback_available(void) { return g_ipv6_loopback_available; } -SOCKET grpc_create_wsa_socket(int family, - int type, - int protocol, - LPWSAPROTOCOL_INFO protocol_info, - GROUP group, +SOCKET grpc_create_wsa_socket(int family, int type, int protocol, + LPWSAPROTOCOL_INFO protocol_info, GROUP group, DWORD flags) { bool is_wsa_no_handle_inherit_set = flags & WSA_FLAG_NO_HANDLE_INHERIT; if (!g_is_wsa_no_handle_inherit_supported && is_wsa_no_handle_inherit_set) { flags ^= WSA_FLAG_NO_HANDLE_INHERIT; } SOCKET sock = WSASocket(family, type, protocol, protocol_info, group, flags); - /* WSA_FLAG_NO_HANDLE_INHERIT may be not supported on the older Windows versions, see + /* WSA_FLAG_NO_HANDLE_INHERIT may be not supported on the older Windows + versions, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx for details. */ if (sock == INVALID_SOCKET && is_wsa_no_handle_inherit_set) { g_is_wsa_no_handle_inherit_supported = false; - sock = WSASocket(family, type, protocol, protocol_info, group, flags ^ WSA_FLAG_NO_HANDLE_INHERIT); + sock = WSASocket(family, type, protocol, protocol_info, group, + flags ^ WSA_FLAG_NO_HANDLE_INHERIT); } return sock; } diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 987325eef71..79c5c8fbee3 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -120,11 +120,8 @@ int grpc_ipv6_loopback_available(void); static bool g_is_wsa_no_handle_inherit_supported = true; -SOCKET grpc_create_wsa_socket(int family, - int type, - int protocol, - LPWSAPROTOCOL_INFO protocol_info, - GROUP group, +SOCKET grpc_create_wsa_socket(int family, int type, int protocol, + LPWSAPROTOCOL_INFO protocol_info, GROUP group, DWORD flags); #endif diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index 881f7670610..5b15ee2c4e6 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -147,8 +147,9 @@ static void tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint, addr = &addr6_v4mapped; } - sock = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + sock = + grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 9c398ebc8a5..db4bb84092b 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -254,8 +254,9 @@ static grpc_error* start_accept_locked(grpc_tcp_listener* port) { return GRPC_ERROR_NONE; } - sock = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + sock = + grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; @@ -492,8 +493,9 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s, addr = &wildcard; } - sock = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + sock = + grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto done; diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 072504f4e38..43a9a066266 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -279,8 +279,9 @@ void OpenAndCloseSocketsStressLoop(int dummy_port, gpr_event* done_ev) { } std::vector sockets; for (size_t i = 0; i < 50; i++) { - SOCKET s = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + SOCKET s = grpc_create_wsa_socket( + AF_INET6, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); ASSERT_TRUE(s != BAD_SOCKET_RETURN_VAL) << "Failed to create TCP ipv6 socket"; gpr_log(GPR_DEBUG, "Opened socket: %d", s); From 0b96d0f71103023b15940893c3f249f36f2d9595 Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Tue, 26 Feb 2019 12:13:18 +0300 Subject: [PATCH 06/12] Check once that WSA_FLAG_NO_HANDLE_INHERIT is supported --- .../dns/c_ares/grpc_ares_ev_driver_windows.cc | 4 +--- src/core/lib/iomgr/endpoint_pair_windows.cc | 10 ++++----- src/core/lib/iomgr/iomgr_windows.cc | 1 + src/core/lib/iomgr/socket_windows.cc | 21 +++++++------------ src/core/lib/iomgr/socket_windows.h | 6 ++---- src/core/lib/iomgr/tcp_client_windows.cc | 5 ++--- src/core/lib/iomgr/tcp_server_windows.cc | 10 ++++----- 7 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc index 5d77fb761f3..5cd988ec1d7 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -442,9 +442,7 @@ class SockToPolledFdMap { */ static ares_socket_t Socket(int af, int type, int protocol, void* user_data) { SockToPolledFdMap* map = static_cast(user_data); - SOCKET s = grpc_create_wsa_socket( - af, type, protocol, nullptr, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + SOCKET s = WSASocket(af, type, protocol, nullptr, 0, grpc_wsa_socket_flags); if (s == INVALID_SOCKET) { return s; } diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index b914e1c6660..ee6a617f61f 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -40,9 +40,8 @@ static void create_sockets(SOCKET sv[2]) { SOCKADDR_IN addr; int addr_len = sizeof(addr); - lst_sock = - grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + lst_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + grpc_wsa_socket_flags); GPR_ASSERT(lst_sock != INVALID_SOCKET); memset(&addr, 0, sizeof(addr)); @@ -54,9 +53,8 @@ static void create_sockets(SOCKET sv[2]) { GPR_ASSERT(getsockname(lst_sock, (grpc_sockaddr*)&addr, &addr_len) != SOCKET_ERROR); - cli_sock = - grpc_create_wsa_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + grpc_wsa_socket_flags); GPR_ASSERT(cli_sock != INVALID_SOCKET); GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, diff --git a/src/core/lib/iomgr/iomgr_windows.cc b/src/core/lib/iomgr/iomgr_windows.cc index e517a6caee4..0e897dafb16 100644 --- a/src/core/lib/iomgr/iomgr_windows.cc +++ b/src/core/lib/iomgr/iomgr_windows.cc @@ -61,6 +61,7 @@ static void iomgr_platform_init(void) { winsock_init(); grpc_iocp_init(); grpc_pollset_global_init(); + grpc_wsa_socket_flags_init(); } static void iomgr_platform_flush(void) { grpc_iocp_flush(); } diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index f55fe674f15..9e5c579c60d 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -181,24 +181,19 @@ int grpc_ipv6_loopback_available(void) { return g_ipv6_loopback_available; } -SOCKET grpc_create_wsa_socket(int family, int type, int protocol, - LPWSAPROTOCOL_INFO protocol_info, GROUP group, - DWORD flags) { - bool is_wsa_no_handle_inherit_set = flags & WSA_FLAG_NO_HANDLE_INHERIT; - if (!g_is_wsa_no_handle_inherit_supported && is_wsa_no_handle_inherit_set) { - flags ^= WSA_FLAG_NO_HANDLE_INHERIT; - } - SOCKET sock = WSASocket(family, type, protocol, protocol_info, group, flags); +void grpc_wsa_socket_flags_init() { + grpc_wsa_socket_flags = WSA_FLAG_OVERLAPPED; /* WSA_FLAG_NO_HANDLE_INHERIT may be not supported on the older Windows versions, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx for details. */ - if (sock == INVALID_SOCKET && is_wsa_no_handle_inherit_set) { - g_is_wsa_no_handle_inherit_supported = false; - sock = WSASocket(family, type, protocol, protocol_info, group, - flags ^ WSA_FLAG_NO_HANDLE_INHERIT); + SOCKET sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, 0, NULL, + grpc_wsa_socket_flags & WSA_FLAG_NO_HANDLE_INHERIT); + if (sock != INVALID_SOCKET) { + /* Windows 7, Windows 2008 R2 with SP1 or later */ + grpc_wsa_socket_flags &= WSA_FLAG_NO_HANDLE_INHERIT; + closesocket(sock); } - return sock; } #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 79c5c8fbee3..0cf70f39a10 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -118,11 +118,9 @@ void grpc_socket_become_ready(grpc_winsocket* winsocket, The value is probed once, and cached for the life of the process. */ int grpc_ipv6_loopback_available(void); -static bool g_is_wsa_no_handle_inherit_supported = true; +static DWORD grpc_wsa_socket_flags = 0; -SOCKET grpc_create_wsa_socket(int family, int type, int protocol, - LPWSAPROTOCOL_INFO protocol_info, GROUP group, - DWORD flags); +void grpc_wsa_socket_flags_init(); #endif diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index 5b15ee2c4e6..147edf4ffe4 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -147,9 +147,8 @@ static void tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint, addr = &addr6_v4mapped; } - sock = - grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + grpc_wsa_socket_flags); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index db4bb84092b..5e0217a5d36 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -254,9 +254,8 @@ static grpc_error* start_accept_locked(grpc_tcp_listener* port) { return GRPC_ERROR_NONE; } - sock = - grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + grpc_wsa_socket_flags); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; @@ -493,9 +492,8 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s, addr = &wildcard; } - sock = - grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, + grpc_wsa_socket_flags); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto done; From 7d1e2015395922ea8d62740466eb95c10483e0ac Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Tue, 26 Feb 2019 12:16:53 +0300 Subject: [PATCH 07/12] Use grpc_wsa_socket_flags in the test/cpp/naming/resolver_component_test.cc --- test/cpp/naming/resolver_component_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 43a9a066266..7410a0e6597 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -279,9 +279,8 @@ void OpenAndCloseSocketsStressLoop(int dummy_port, gpr_event* done_ev) { } std::vector sockets; for (size_t i = 0; i < 50; i++) { - SOCKET s = grpc_create_wsa_socket( - AF_INET6, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + SOCKET s = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, + nullptr, 0, grpc_wsa_socket_flags); ASSERT_TRUE(s != BAD_SOCKET_RETURN_VAL) << "Failed to create TCP ipv6 socket"; gpr_log(GPR_DEBUG, "Opened socket: %d", s); From 8232d698207899d656ace9a27edf921a441db82b Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Tue, 26 Feb 2019 12:32:55 +0300 Subject: [PATCH 08/12] Reverted changes in the test/cpp/naming/resolver_component_test.cc --- test/cpp/naming/resolver_component_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index 7410a0e6597..9532529e45d 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -279,8 +279,8 @@ void OpenAndCloseSocketsStressLoop(int dummy_port, gpr_event* done_ev) { } std::vector sockets; for (size_t i = 0; i < 50; i++) { - SOCKET s = grpc_create_wsa_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, - nullptr, 0, grpc_wsa_socket_flags); + SOCKET s = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, + WSA_FLAG_OVERLAPPED); ASSERT_TRUE(s != BAD_SOCKET_RETURN_VAL) << "Failed to create TCP ipv6 socket"; gpr_log(GPR_DEBUG, "Opened socket: %d", s); From 6e07d04c928ea1b23742a0662cceabef5a1ae107 Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Tue, 26 Feb 2019 13:48:28 +0300 Subject: [PATCH 09/12] Fixed silly error --- src/core/lib/iomgr/socket_windows.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 9e5c579c60d..1794b162223 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -188,10 +188,10 @@ void grpc_wsa_socket_flags_init() { https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx for details. */ SOCKET sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, 0, NULL, - grpc_wsa_socket_flags & WSA_FLAG_NO_HANDLE_INHERIT); + grpc_wsa_socket_flags | WSA_FLAG_NO_HANDLE_INHERIT); if (sock != INVALID_SOCKET) { /* Windows 7, Windows 2008 R2 with SP1 or later */ - grpc_wsa_socket_flags &= WSA_FLAG_NO_HANDLE_INHERIT; + grpc_wsa_socket_flags |= WSA_FLAG_NO_HANDLE_INHERIT; closesocket(sock); } } From 6698cf87b389420794390ca7d5c3327f06cbf1aa Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Tue, 26 Feb 2019 15:41:11 +0300 Subject: [PATCH 10/12] Single instances of the grpc_wsa_socket_flags --- src/core/lib/iomgr/socket_windows.cc | 2 ++ src/core/lib/iomgr/socket_windows.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 1794b162223..9b9b745829e 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -39,6 +39,8 @@ #include "src/core/lib/iomgr/sockaddr_windows.h" #include "src/core/lib/iomgr/socket_windows.h" +DWORD grpc_wsa_socket_flags; + grpc_winsocket* grpc_winsocket_create(SOCKET socket, const char* name) { char* final_name; grpc_winsocket* r = (grpc_winsocket*)gpr_malloc(sizeof(grpc_winsocket)); diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 0cf70f39a10..9a5caef9f52 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -118,7 +118,7 @@ void grpc_socket_become_ready(grpc_winsocket* winsocket, The value is probed once, and cached for the life of the process. */ int grpc_ipv6_loopback_available(void); -static DWORD grpc_wsa_socket_flags = 0; +extern DWORD grpc_wsa_socket_flags; void grpc_wsa_socket_flags_init(); From b3254101418d2c733380f532a0e80da6e3042194 Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Tue, 12 Mar 2019 18:17:09 +0300 Subject: [PATCH 11/12] Added grpc_get_default_wsa_socket_flags() --- .../resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc | 3 ++- src/core/lib/iomgr/endpoint_pair_windows.cc | 4 ++-- src/core/lib/iomgr/socket_windows.cc | 4 +++- src/core/lib/iomgr/socket_windows.h | 2 ++ src/core/lib/iomgr/tcp_client_windows.cc | 2 +- src/core/lib/iomgr/tcp_server_windows.cc | 4 ++-- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc index 5cd988ec1d7..69a206ba847 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -442,7 +442,8 @@ class SockToPolledFdMap { */ static ares_socket_t Socket(int af, int type, int protocol, void* user_data) { SockToPolledFdMap* map = static_cast(user_data); - SOCKET s = WSASocket(af, type, protocol, nullptr, 0, grpc_wsa_socket_flags); + SOCKET s = WSASocket(af, type, protocol, nullptr, 0, + grpc_get_default_wsa_socket_flags()); if (s == INVALID_SOCKET) { return s; } diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index ee6a617f61f..9962809a27b 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -41,7 +41,7 @@ static void create_sockets(SOCKET sv[2]) { int addr_len = sizeof(addr); lst_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - grpc_wsa_socket_flags); + grpc_get_default_wsa_socket_flags()); GPR_ASSERT(lst_sock != INVALID_SOCKET); memset(&addr, 0, sizeof(addr)); @@ -54,7 +54,7 @@ static void create_sockets(SOCKET sv[2]) { SOCKET_ERROR); cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - grpc_wsa_socket_flags); + grpc_get_default_wsa_socket_flags()); GPR_ASSERT(cli_sock != INVALID_SOCKET); GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 9b9b745829e..2026c95062f 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -183,13 +183,15 @@ int grpc_ipv6_loopback_available(void) { return g_ipv6_loopback_available; } +DWORD grpc_get_default_wsa_socket_flags() { return grpc_wsa_socket_flags; } + void grpc_wsa_socket_flags_init() { grpc_wsa_socket_flags = WSA_FLAG_OVERLAPPED; /* WSA_FLAG_NO_HANDLE_INHERIT may be not supported on the older Windows versions, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx for details. */ - SOCKET sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, 0, NULL, + SOCKET sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, grpc_wsa_socket_flags | WSA_FLAG_NO_HANDLE_INHERIT); if (sock != INVALID_SOCKET) { /* Windows 7, Windows 2008 R2 with SP1 or later */ diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 9a5caef9f52..32b88880569 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -122,6 +122,8 @@ extern DWORD grpc_wsa_socket_flags; void grpc_wsa_socket_flags_init(); +DWORD grpc_get_default_wsa_socket_flags(); + #endif #endif /* GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H */ diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index 147edf4ffe4..264af452618 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -148,7 +148,7 @@ static void tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint, } sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - grpc_wsa_socket_flags); + grpc_get_default_wsa_socket_flags()); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 5e0217a5d36..7ac423440e2 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -255,7 +255,7 @@ static grpc_error* start_accept_locked(grpc_tcp_listener* port) { } sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - grpc_wsa_socket_flags); + grpc_get_default_wsa_socket_flags()); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto failure; @@ -493,7 +493,7 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s, } sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - grpc_wsa_socket_flags); + grpc_get_default_wsa_socket_flags()); if (sock == INVALID_SOCKET) { error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket"); goto done; From c792aae3286454a0fd035dc8f8d79da02c2a9a63 Mon Sep 17 00:00:00 2001 From: frazenshtein Date: Wed, 13 Mar 2019 10:29:41 +0300 Subject: [PATCH 12/12] Removed grpc_wsa_socket_flags variable from the header, renamed to s_wsa_socket_flags --- src/core/lib/iomgr/socket_windows.cc | 10 +++++----- src/core/lib/iomgr/socket_windows.h | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/lib/iomgr/socket_windows.cc b/src/core/lib/iomgr/socket_windows.cc index 2026c95062f..c87cfa8e831 100644 --- a/src/core/lib/iomgr/socket_windows.cc +++ b/src/core/lib/iomgr/socket_windows.cc @@ -39,7 +39,7 @@ #include "src/core/lib/iomgr/sockaddr_windows.h" #include "src/core/lib/iomgr/socket_windows.h" -DWORD grpc_wsa_socket_flags; +static DWORD s_wsa_socket_flags; grpc_winsocket* grpc_winsocket_create(SOCKET socket, const char* name) { char* final_name; @@ -183,19 +183,19 @@ int grpc_ipv6_loopback_available(void) { return g_ipv6_loopback_available; } -DWORD grpc_get_default_wsa_socket_flags() { return grpc_wsa_socket_flags; } +DWORD grpc_get_default_wsa_socket_flags() { return s_wsa_socket_flags; } void grpc_wsa_socket_flags_init() { - grpc_wsa_socket_flags = WSA_FLAG_OVERLAPPED; + s_wsa_socket_flags = WSA_FLAG_OVERLAPPED; /* WSA_FLAG_NO_HANDLE_INHERIT may be not supported on the older Windows versions, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx for details. */ SOCKET sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, - grpc_wsa_socket_flags | WSA_FLAG_NO_HANDLE_INHERIT); + s_wsa_socket_flags | WSA_FLAG_NO_HANDLE_INHERIT); if (sock != INVALID_SOCKET) { /* Windows 7, Windows 2008 R2 with SP1 or later */ - grpc_wsa_socket_flags |= WSA_FLAG_NO_HANDLE_INHERIT; + s_wsa_socket_flags |= WSA_FLAG_NO_HANDLE_INHERIT; closesocket(sock); } } diff --git a/src/core/lib/iomgr/socket_windows.h b/src/core/lib/iomgr/socket_windows.h index 32b88880569..5fed6909e6f 100644 --- a/src/core/lib/iomgr/socket_windows.h +++ b/src/core/lib/iomgr/socket_windows.h @@ -118,8 +118,6 @@ void grpc_socket_become_ready(grpc_winsocket* winsocket, The value is probed once, and cached for the life of the process. */ int grpc_ipv6_loopback_available(void); -extern DWORD grpc_wsa_socket_flags; - void grpc_wsa_socket_flags_init(); DWORD grpc_get_default_wsa_socket_flags();