win: move logic to set socket non-inheritable to uv_tcp_set_socket
PR-URL: https://github.com/libuv/libuv/pull/400 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
fb5df542ac
commit
2dddd565fd
@ -78,8 +78,11 @@ static int uv__tcp_keepalive(uv_tcp_t* handle, SOCKET socket, int enable, unsign
|
||||
}
|
||||
|
||||
|
||||
static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle,
|
||||
SOCKET socket, int family, int imported) {
|
||||
static int uv_tcp_set_socket(uv_loop_t* loop,
|
||||
uv_tcp_t* handle,
|
||||
SOCKET socket,
|
||||
int family,
|
||||
int imported) {
|
||||
DWORD yes = 1;
|
||||
int non_ifs_lsp;
|
||||
int err;
|
||||
@ -92,6 +95,10 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle,
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
/* Make the socket non-inheritable */
|
||||
if (!SetHandleInformation((HANDLE) socket, HANDLE_FLAG_INHERIT, 0))
|
||||
return GetLastError();
|
||||
|
||||
/* Associate it with the I/O completion port. */
|
||||
/* Use uv_handle_t pointer as completion key. */
|
||||
if (CreateIoCompletionPort((HANDLE)socket,
|
||||
@ -268,13 +275,6 @@ static int uv_tcp_try_bind(uv_tcp_t* handle,
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
/* Make the socket non-inheritable */
|
||||
if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
|
||||
err = GetLastError();
|
||||
closesocket(sock);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = uv_tcp_set_socket(handle->loop, handle, sock, addr->sa_family, 0);
|
||||
if (err) {
|
||||
closesocket(sock);
|
||||
@ -381,15 +381,6 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make the socket non-inheritable */
|
||||
if (!SetHandleInformation((HANDLE) accept_socket, HANDLE_FLAG_INHERIT, 0)) {
|
||||
SET_REQ_ERROR(req, GetLastError());
|
||||
uv_insert_pending_req(loop, (uv_req_t*)req);
|
||||
handle->reqs_pending++;
|
||||
closesocket(accept_socket);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Prepare the overlapped structure. */
|
||||
memset(&(req->u.io.overlapped), 0, sizeof(req->u.io.overlapped));
|
||||
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
|
||||
@ -1166,12 +1157,6 @@ int uv_tcp_import(uv_tcp_t* tcp, uv__ipc_socket_info_ex* socket_info_ex,
|
||||
return WSAGetLastError();
|
||||
}
|
||||
|
||||
if (!SetHandleInformation((HANDLE) socket, HANDLE_FLAG_INHERIT, 0)) {
|
||||
err = GetLastError();
|
||||
closesocket(socket);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = uv_tcp_set_socket(tcp->loop,
|
||||
tcp,
|
||||
socket,
|
||||
@ -1427,11 +1412,6 @@ int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) {
|
||||
return uv_translate_sys_error(GetLastError());
|
||||
}
|
||||
|
||||
/* Make the socket non-inheritable */
|
||||
if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
|
||||
return uv_translate_sys_error(GetLastError());
|
||||
}
|
||||
|
||||
err = uv_tcp_set_socket(handle->loop,
|
||||
handle,
|
||||
sock,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user