diff --git a/src/node_child_process_win32.cc b/src/node_child_process_win32.cc index 4dba282e58..2734f25092 100644 --- a/src/node_child_process_win32.cc +++ b/src/node_child_process_win32.cc @@ -321,8 +321,8 @@ void ChildProcess::close_stdio_handles(ChildProcess *child) { // take some time and would deadlock if done in the main thread. for (int i = 0; i < 3; i++) { if (!child->got_custom_fds_[i]) { - wsa_disconnect_ex((SOCKET)child->stdio_handles_[i], NULL, 0, 0); - closesocket((SOCKET)child->stdio_handles_[i]); + shutdown(reinterpret_cast(child->stdio_handles_[i]), SD_BOTH); + closesocket(reinterpret_cast(child->stdio_handles_[i])); } } } @@ -742,6 +742,10 @@ Handle ChildProcess::Spawn(const Arguments& args) { SOCKET_ERROR) wsa_perror("ioctlsocket"); + // Make parent handle non-inheritable + if (!SetHandleInformation(parent_handle, HANDLE_FLAG_INHERIT, 0)) + winapi_perror("SetHandleInformation"); + // Make child handle inheritable if (!SetHandleInformation(child_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) @@ -873,4 +877,4 @@ void ChildProcess::Initialize(Handle target) { } // namespace node -NODE_MODULE(node_child_process, node::ChildProcess::Initialize); \ No newline at end of file +NODE_MODULE(node_child_process, node::ChildProcess::Initialize); diff --git a/src/node_file.cc b/src/node_file.cc index e85ccc78d1..40b8362ca5 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -56,8 +56,8 @@ static inline bool SetCloseOnExec(int fd) { #ifdef __POSIX__ return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); #else // __MINGW32__ - /* no-op on windows */ - return false; + return SetHandleInformation(reinterpret_cast(_get_osfhandle(fd)), + HANDLE_FLAG_INHERIT, 0) != 0; #endif } diff --git a/src/node_net.cc b/src/node_net.cc index 17f4687953..5a2d308266 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -92,14 +92,15 @@ static Persistent recv_msg_template; } -#ifdef __POSIX__ - static inline bool SetCloseOnExec(int fd) { +#ifdef __POSIX__ return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); +#else // __MINGW32__ + return SetHandleInformation(reinterpret_cast(_get_osfhandle(fd)), + HANDLE_FLAG_INHERIT, 0) != 0; +#endif } -#endif // __POSIX__ - static inline bool SetNonBlock(int fd) { #ifdef __MINGW32__ @@ -115,12 +116,11 @@ static inline bool SetSockFlags(int fd) { #ifdef __MINGW32__ BOOL flags = TRUE; setsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_REUSEADDR, (const char *)&flags, sizeof(flags)); - return SetNonBlock(fd); #else // __POSIX__ int flags = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags)); - return SetNonBlock(fd) && SetCloseOnExec(fd); #endif + return SetNonBlock(fd) && SetCloseOnExec(fd); } diff --git a/src/platform_win32_winsock.cc b/src/platform_win32_winsock.cc index cecb5a444a..df193d9c86 100644 --- a/src/platform_win32_winsock.cc +++ b/src/platform_win32_winsock.cc @@ -129,14 +129,6 @@ void wsa_perror(const char *prefix) { } -/* - * Wrapper for DisconnectEx extension function - */ -BOOL wsa_disconnect_ex(SOCKET socket, OVERLAPPED *overlapped, DWORD flags, DWORD reserved) { - return wsexf.DisconnectEx(socket, overlapped, flags, reserved); -} - - /* * Retrieves a pointer to a WSAPROTOCOL_INFOW structure * related to a certain winsock protocol from the cache @@ -422,6 +414,7 @@ inline static void wsa_get_extension_function(SOCKET socket, GUID guid, void **t * Retrieves the needed winsock extension function pointers for the tcp/ip subsystem, * storing them in the `wsexf` cache */ +/* inline static void wsa_init_extension_functions() { SOCKET dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); @@ -431,14 +424,15 @@ inline static void wsa_init_extension_functions() { return; } - //wsa_get_extension_function(dummy, WSAID_CONNECTEX, (void**)&wsexf.ConnectEx ); - //wsa_get_extension_function(dummy, WSAID_ACCEPTEX, (void**)&wsexf.AcceptEx ); - //wsa_get_extension_function(dummy, WSAID_GETACCEPTEXSOCKADDRS, (void**)&wsexf.GetAcceptExSockAddrs); + wsa_get_extension_function(dummy, WSAID_CONNECTEX, (void**)&wsexf.ConnectEx ); + wsa_get_extension_function(dummy, WSAID_ACCEPTEX, (void**)&wsexf.AcceptEx ); + wsa_get_extension_function(dummy, WSAID_GETACCEPTEXSOCKADDRS, (void**)&wsexf.GetAcceptExSockAddrs); wsa_get_extension_function(dummy, WSAID_DISCONNECTEX, (void**)&wsexf.DisconnectEx ); - //wsa_get_extension_function(dummy, WSAID_TRANSMITFILE, (void**)&wsexf.TransmitFile ); + wsa_get_extension_function(dummy, WSAID_TRANSMITFILE, (void**)&wsexf.TransmitFile ); closesocket(dummy); } +*/ /* @@ -451,7 +445,7 @@ void wsa_init() { } wsa_init_proto_info_cache(); - wsa_init_extension_functions(); + //wsa_init_extension_functions(); } diff --git a/src/platform_win32_winsock.h b/src/platform_win32_winsock.h index f292682243..f78329daca 100644 --- a/src/platform_win32_winsock.h +++ b/src/platform_win32_winsock.h @@ -15,7 +15,6 @@ void wsa_init(); void wsa_perror(const char* prefix = ""); SOCKET wsa_sync_socket(int af, int type, int proto); -BOOL wsa_disconnect_ex(SOCKET socket, OVERLAPPED *overlapped, DWORD flags, DWORD reserved); int wsa_socketpair(int af, int type, int proto, SOCKET sock[2]); int wsa_sync_async_socketpair(int af, int type, int proto, SOCKET *syncSocket, SOCKET *asyncSocket);