Browse Source

Windows: child process fixes

v0.7.4-release
Bert Belder 14 years ago
committed by Ryan Dahl
parent
commit
36846f9b6b
  1. 8
      src/node_child_process_win32.cc
  2. 4
      src/node_file.cc
  3. 12
      src/node_net.cc
  4. 20
      src/platform_win32_winsock.cc
  5. 1
      src/platform_win32_winsock.h

8
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. // take some time and would deadlock if done in the main thread.
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (!child->got_custom_fds_[i]) { if (!child->got_custom_fds_[i]) {
wsa_disconnect_ex((SOCKET)child->stdio_handles_[i], NULL, 0, 0); shutdown(reinterpret_cast<SOCKET>(child->stdio_handles_[i]), SD_BOTH);
closesocket((SOCKET)child->stdio_handles_[i]); closesocket(reinterpret_cast<SOCKET>(child->stdio_handles_[i]));
} }
} }
} }
@ -742,6 +742,10 @@ Handle<Value> ChildProcess::Spawn(const Arguments& args) {
SOCKET_ERROR) SOCKET_ERROR)
wsa_perror("ioctlsocket"); wsa_perror("ioctlsocket");
// Make parent handle non-inheritable
if (!SetHandleInformation(parent_handle, HANDLE_FLAG_INHERIT, 0))
winapi_perror("SetHandleInformation");
// Make child handle inheritable // Make child handle inheritable
if (!SetHandleInformation(child_handle, HANDLE_FLAG_INHERIT, if (!SetHandleInformation(child_handle, HANDLE_FLAG_INHERIT,
HANDLE_FLAG_INHERIT)) HANDLE_FLAG_INHERIT))

4
src/node_file.cc

@ -56,8 +56,8 @@ static inline bool SetCloseOnExec(int fd) {
#ifdef __POSIX__ #ifdef __POSIX__
return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1);
#else // __MINGW32__ #else // __MINGW32__
/* no-op on windows */ return SetHandleInformation(reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
return false; HANDLE_FLAG_INHERIT, 0) != 0;
#endif #endif
} }

12
src/node_net.cc

@ -92,14 +92,15 @@ static Persistent<FunctionTemplate> recv_msg_template;
} }
#ifdef __POSIX__
static inline bool SetCloseOnExec(int fd) { static inline bool SetCloseOnExec(int fd) {
#ifdef __POSIX__
return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); 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) { static inline bool SetNonBlock(int fd) {
#ifdef __MINGW32__ #ifdef __MINGW32__
@ -115,12 +116,11 @@ static inline bool SetSockFlags(int fd) {
#ifdef __MINGW32__ #ifdef __MINGW32__
BOOL flags = TRUE; BOOL flags = TRUE;
setsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_REUSEADDR, (const char *)&flags, sizeof(flags)); setsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_REUSEADDR, (const char *)&flags, sizeof(flags));
return SetNonBlock(fd);
#else // __POSIX__ #else // __POSIX__
int flags = 1; int flags = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags)); setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags));
return SetNonBlock(fd) && SetCloseOnExec(fd);
#endif #endif
return SetNonBlock(fd) && SetCloseOnExec(fd);
} }

20
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 * Retrieves a pointer to a WSAPROTOCOL_INFOW structure
* related to a certain winsock protocol from the cache * 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, * Retrieves the needed winsock extension function pointers for the tcp/ip subsystem,
* storing them in the `wsexf` cache * storing them in the `wsexf` cache
*/ */
/*
inline static void wsa_init_extension_functions() { inline static void wsa_init_extension_functions() {
SOCKET dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); SOCKET dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
@ -431,14 +424,15 @@ inline static void wsa_init_extension_functions() {
return; return;
} }
//wsa_get_extension_function(dummy, WSAID_CONNECTEX, (void**)&wsexf.ConnectEx ); 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_ACCEPTEX, (void**)&wsexf.AcceptEx );
//wsa_get_extension_function(dummy, WSAID_GETACCEPTEXSOCKADDRS, (void**)&wsexf.GetAcceptExSockAddrs); 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_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); closesocket(dummy);
} }
*/
/* /*
@ -451,7 +445,7 @@ void wsa_init() {
} }
wsa_init_proto_info_cache(); wsa_init_proto_info_cache();
wsa_init_extension_functions(); //wsa_init_extension_functions();
} }

1
src/platform_win32_winsock.h

@ -15,7 +15,6 @@ void wsa_init();
void wsa_perror(const char* prefix = ""); void wsa_perror(const char* prefix = "");
SOCKET wsa_sync_socket(int af, int type, int proto); 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_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); int wsa_sync_async_socketpair(int af, int type, int proto, SOCKET *syncSocket, SOCKET *asyncSocket);

Loading…
Cancel
Save