// 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<SOCKET>(child->stdio_handles_[i]), SD_BOTH);
+ closesocket(reinterpret_cast<SOCKET>(child->stdio_handles_[i]));
}
}
}
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))
} // namespace node
-NODE_MODULE(node_child_process, node::ChildProcess::Initialize);
\ No newline at end of file
+NODE_MODULE(node_child_process, node::ChildProcess::Initialize);
#ifdef __POSIX__
return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1);
#else // __MINGW32__
- /* no-op on windows */
- return false;
+ return SetHandleInformation(reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
+ HANDLE_FLAG_INHERIT, 0) != 0;
#endif
}
}
-#ifdef __POSIX__
-
static inline bool SetCloseOnExec(int fd) {
+#ifdef __POSIX__
return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1);
+#else // __MINGW32__
+ return SetHandleInformation(reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
+ HANDLE_FLAG_INHERIT, 0) != 0;
+#endif
}
-#endif // __POSIX__
-
static inline bool SetNonBlock(int fd) {
#ifdef __MINGW32__
#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);
}
\r
\r
/*\r
- * Wrapper for DisconnectEx extension function\r
- */\r
-BOOL wsa_disconnect_ex(SOCKET socket, OVERLAPPED *overlapped, DWORD flags, DWORD reserved) {\r
- return wsexf.DisconnectEx(socket, overlapped, flags, reserved);\r
-}\r
-\r
-\r
-/*\r
* Retrieves a pointer to a WSAPROTOCOL_INFOW structure\r
* related to a certain winsock protocol from the cache\r
*/\r
* Retrieves the needed winsock extension function pointers for the tcp/ip subsystem,\r
* storing them in the `wsexf` cache\r
*/\r
+/*\r
inline static void wsa_init_extension_functions() {\r
SOCKET dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);\r
\r
return;\r
}\r
\r
- //wsa_get_extension_function(dummy, WSAID_CONNECTEX, (void**)&wsexf.ConnectEx );\r
- //wsa_get_extension_function(dummy, WSAID_ACCEPTEX, (void**)&wsexf.AcceptEx );\r
- //wsa_get_extension_function(dummy, WSAID_GETACCEPTEXSOCKADDRS, (void**)&wsexf.GetAcceptExSockAddrs);\r
+ wsa_get_extension_function(dummy, WSAID_CONNECTEX, (void**)&wsexf.ConnectEx );\r
+ wsa_get_extension_function(dummy, WSAID_ACCEPTEX, (void**)&wsexf.AcceptEx );\r
+ wsa_get_extension_function(dummy, WSAID_GETACCEPTEXSOCKADDRS, (void**)&wsexf.GetAcceptExSockAddrs);\r
wsa_get_extension_function(dummy, WSAID_DISCONNECTEX, (void**)&wsexf.DisconnectEx );\r
- //wsa_get_extension_function(dummy, WSAID_TRANSMITFILE, (void**)&wsexf.TransmitFile );\r
+ wsa_get_extension_function(dummy, WSAID_TRANSMITFILE, (void**)&wsexf.TransmitFile );\r
\r
closesocket(dummy);\r
}\r
+*/\r
\r
\r
/*\r
}\r
\r
wsa_init_proto_info_cache();\r
- wsa_init_extension_functions();\r
+ //wsa_init_extension_functions();\r
}\r
\r
\r
void wsa_perror(const char* prefix = "");\r
\r
SOCKET wsa_sync_socket(int af, int type, int proto);\r
-BOOL wsa_disconnect_ex(SOCKET socket, OVERLAPPED *overlapped, DWORD flags, DWORD reserved);\r
\r
int wsa_socketpair(int af, int type, int proto, SOCKET sock[2]);\r
int wsa_sync_async_socketpair(int af, int type, int proto, SOCKET *syncSocket, SOCKET *asyncSocket);\r