FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Windows: child process fixes · baoping/node@36846f9 · GitHub

Commit 36846f9

Browse files
authored andcommitted
Windows: child process fixes
1 parent 519dc2c commit 36846f9

5 files changed

Lines changed: 22 additions & 25 deletions

File tree

‎src/node_child_process_win32.cc‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ void ChildProcess::close_stdio_handles(ChildProcess *child) {
321321
// take some time and would deadlock if done in the main thread.
322322
for (int i = 0; i < 3; i++) {
323323
if (!child->got_custom_fds_[i]) {
324-
wsa_disconnect_ex((SOCKET)child->stdio_handles_[i], NULL, 0, 0);
325-
closesocket((SOCKET)child->stdio_handles_[i]);
324+
shutdown(reinterpret_cast<SOCKET>(child->stdio_handles_[i]), SD_BOTH);
325+
closesocket(reinterpret_cast<SOCKET>(child->stdio_handles_[i]));
326326
}
327327
}
328328
}
@@ -742,6 +742,10 @@ Handle<Value> ChildProcess::Spawn(const Arguments& args) {
742742
SOCKET_ERROR)
743743
wsa_perror("ioctlsocket");
744744

745+
// Make parent handle non-inheritable
746+
if (!SetHandleInformation(parent_handle, HANDLE_FLAG_INHERIT, 0))
747+
winapi_perror("SetHandleInformation");
748+
745749
// Make child handle inheritable
746750
if (!SetHandleInformation(child_handle, HANDLE_FLAG_INHERIT,
747751
HANDLE_FLAG_INHERIT))
@@ -873,4 +877,4 @@ void ChildProcess::Initialize(Handle<Object> target) {
873877

874878
} // namespace node
875879

876-
NODE_MODULE(node_child_process, node::ChildProcess::Initialize);
880+
NODE_MODULE(node_child_process, node::ChildProcess::Initialize);

‎src/node_file.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static inline bool SetCloseOnExec(int fd) {
5656
#ifdef __POSIX__
5757
return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1);
5858
#else // __MINGW32__
59-
/* no-op on windows */
60-
return false;
59+
return SetHandleInformation(reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
60+
HANDLE_FLAG_INHERIT, 0) != 0;
6161
#endif
6262
}
6363

‎src/node_net.cc‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ static Persistent<FunctionTemplate> recv_msg_template;
9292
}
9393

9494

95-
#ifdef __POSIX__
96-
9795
static inline bool SetCloseOnExec(int fd) {
96+
#ifdef __POSIX__
9897
return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1);
98+
#else // __MINGW32__
99+
return SetHandleInformation(reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
100+
HANDLE_FLAG_INHERIT, 0) != 0;
101+
#endif
99102
}
100103

101-
#endif // __POSIX__
102-
103104

104105
static inline bool SetNonBlock(int fd) {
105106
#ifdef __MINGW32__
@@ -115,12 +116,11 @@ static inline bool SetSockFlags(int fd) {
115116
#ifdef __MINGW32__
116117
BOOL flags = TRUE;
117118
setsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_REUSEADDR, (const char *)&flags, sizeof(flags));
118-
return SetNonBlock(fd);
119119
#else // __POSIX__
120120
int flags = 1;
121121
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags));
122-
return SetNonBlock(fd) && SetCloseOnExec(fd);
123122
#endif
123+
return SetNonBlock(fd) && SetCloseOnExec(fd);
124124
}
125125

126126

‎src/platform_win32_winsock.cc‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ void wsa_perror(const char *prefix) {
129129
}
130130

131131

132-
/*
133-
* Wrapper for DisconnectEx extension function
134-
*/
135-
BOOL wsa_disconnect_ex(SOCKET socket, OVERLAPPED *overlapped, DWORD flags, DWORD reserved) {
136-
return wsexf.DisconnectEx(socket, overlapped, flags, reserved);
137-
}
138-
139-
140132
/*
141133
* Retrieves a pointer to a WSAPROTOCOL_INFOW structure
142134
* 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
422414
* Retrieves the needed winsock extension function pointers for the tcp/ip subsystem,
423415
* storing them in the `wsexf` cache
424416
*/
417+
/*
425418
inline static void wsa_init_extension_functions() {
426419
SOCKET dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
427420
@@ -431,14 +424,15 @@ inline static void wsa_init_extension_functions() {
431424
return;
432425
}
433426
434-
//wsa_get_extension_function(dummy, WSAID_CONNECTEX, (void**)&wsexf.ConnectEx );
435-
//wsa_get_extension_function(dummy, WSAID_ACCEPTEX, (void**)&wsexf.AcceptEx );
436-
//wsa_get_extension_function(dummy, WSAID_GETACCEPTEXSOCKADDRS, (void**)&wsexf.GetAcceptExSockAddrs);
427+
wsa_get_extension_function(dummy, WSAID_CONNECTEX, (void**)&wsexf.ConnectEx );
428+
wsa_get_extension_function(dummy, WSAID_ACCEPTEX, (void**)&wsexf.AcceptEx );
429+
wsa_get_extension_function(dummy, WSAID_GETACCEPTEXSOCKADDRS, (void**)&wsexf.GetAcceptExSockAddrs);
437430
wsa_get_extension_function(dummy, WSAID_DISCONNECTEX, (void**)&wsexf.DisconnectEx );
438-
//wsa_get_extension_function(dummy, WSAID_TRANSMITFILE, (void**)&wsexf.TransmitFile );
431+
wsa_get_extension_function(dummy, WSAID_TRANSMITFILE, (void**)&wsexf.TransmitFile );
439432
440433
closesocket(dummy);
441434
}
435+
*/
442436

443437

444438
/*
@@ -451,7 +445,7 @@ void wsa_init() {
451445
}
452446

453447
wsa_init_proto_info_cache();
454-
wsa_init_extension_functions();
448+
//wsa_init_extension_functions();
455449
}
456450

457451

‎src/platform_win32_winsock.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ void wsa_init();
1515
void wsa_perror(const char* prefix = "");
1616

1717
SOCKET wsa_sync_socket(int af, int type, int proto);
18-
BOOL wsa_disconnect_ex(SOCKET socket, OVERLAPPED *overlapped, DWORD flags, DWORD reserved);
1918

2019
int wsa_socketpair(int af, int type, int proto, SOCKET sock[2]);
2120
int wsa_sync_async_socketpair(int af, int type, int proto, SOCKET *syncSocket, SOCKET *asyncSocket);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL