Commit 5fe6ddfd authored by unknown's avatar unknown

On Windows, preventing sockets to be inherited by child processes.

parent 5dc44a63
...@@ -57,6 +57,12 @@ zmq::fd_t zmq::open_socket (int domain_, int type_, int protocol_) ...@@ -57,6 +57,12 @@ zmq::fd_t zmq::open_socket (int domain_, int type_, int protocol_)
errno_assert (rc != -1); errno_assert (rc != -1);
#endif #endif
// On Windows, preventing sockets to be inherited by child processes.
#if defined ZMQ_HAVE_WINDOWS && defined HANDLE_FLAG_INHERIT
BOOL brc = SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
#endif
return s; return s;
} }
......
...@@ -288,6 +288,10 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_) ...@@ -288,6 +288,10 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
*w_ = WSASocket (AF_INET, SOCK_STREAM, 0, NULL, 0, 0); *w_ = WSASocket (AF_INET, SOCK_STREAM, 0, NULL, 0, 0);
wsa_assert (*w_ != INVALID_SOCKET); wsa_assert (*w_ != INVALID_SOCKET);
// On Windows, preventing sockets to be inherited by child processes.
BOOL brc = SetHandleInformation ((HANDLE) *w_, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
// Set TCP_NODELAY on writer socket. // Set TCP_NODELAY on writer socket.
rc = setsockopt (*w_, IPPROTO_TCP, TCP_NODELAY, rc = setsockopt (*w_, IPPROTO_TCP, TCP_NODELAY,
(char *)&tcp_nodelay, sizeof (tcp_nodelay)); (char *)&tcp_nodelay, sizeof (tcp_nodelay));
...@@ -301,12 +305,16 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_) ...@@ -301,12 +305,16 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
*r_ = accept (listener, NULL, NULL); *r_ = accept (listener, NULL, NULL);
wsa_assert (*r_ != INVALID_SOCKET); wsa_assert (*r_ != INVALID_SOCKET);
// On Windows, preventing sockets to be inherited by child processes.
brc = SetHandleInformation ((HANDLE) *r_, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
// We don't need the listening socket anymore. Close it. // We don't need the listening socket anymore. Close it.
rc = closesocket (listener); rc = closesocket (listener);
wsa_assert (rc != SOCKET_ERROR); wsa_assert (rc != SOCKET_ERROR);
// Exit the critical section. // Exit the critical section.
BOOL brc = SetEvent (sync); brc = SetEvent (sync);
win_assert (brc != 0); win_assert (brc != 0);
return 0; return 0;
......
...@@ -164,6 +164,9 @@ int zmq::tcp_listener_t::set_address (const char *addr_) ...@@ -164,6 +164,9 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
wsa_error_to_errno (); wsa_error_to_errno ();
return -1; return -1;
} }
// On Windows, preventing sockets to be inherited by child processes.
BOOL brc = SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
#else #else
if (s == -1) if (s == -1)
return -1; return -1;
...@@ -227,6 +230,9 @@ zmq::fd_t zmq::tcp_listener_t::accept () ...@@ -227,6 +230,9 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
WSAGetLastError () == WSAECONNRESET); WSAGetLastError () == WSAECONNRESET);
return retired_fd; return retired_fd;
} }
// On Windows, preventing sockets to be inherited by child processes.
BOOL brc = SetHandleInformation ((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
win_assert (brc);
#else #else
if (sock == -1) { if (sock == -1) {
errno_assert (errno == EAGAIN || errno == EWOULDBLOCK || errno_assert (errno == EAGAIN || errno == EWOULDBLOCK ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment