Cygwin: sockets: move common settings into set_socket_handle()
Move setting address family, socket type and descriptor flags into fhandler_socket::set_socket_handle method. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
bc9b30ea77
commit
cff85eaddc
@ -557,7 +557,7 @@ class fhandler_socket: public fhandler_base
|
|||||||
} status;
|
} status;
|
||||||
|
|
||||||
#ifdef __INSIDE_CYGWIN_NET__
|
#ifdef __INSIDE_CYGWIN_NET__
|
||||||
int set_socket_handle (SOCKET sock);
|
int set_socket_handle (SOCKET sock, int af, int type, int flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -263,9 +263,9 @@ fhandler_socket::open (int flags, mode_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fhandler_socket::set_socket_handle (SOCKET sock)
|
fhandler_socket::set_socket_handle (SOCKET sock, int af, int type, int flags)
|
||||||
{
|
{
|
||||||
DWORD flags;
|
DWORD hdl_flags;
|
||||||
bool lsp_fixup = false;
|
bool lsp_fixup = false;
|
||||||
|
|
||||||
/* Usually sockets are inheritable IFS objects. Unfortunately some virus
|
/* Usually sockets are inheritable IFS objects. Unfortunately some virus
|
||||||
@ -288,8 +288,8 @@ fhandler_socket::set_socket_handle (SOCKET sock)
|
|||||||
If that doesn't work for some reason, mark the sockets for duplication
|
If that doesn't work for some reason, mark the sockets for duplication
|
||||||
via WSADuplicateSocket/WSASocket. This requires to start the child
|
via WSADuplicateSocket/WSASocket. This requires to start the child
|
||||||
process in SUSPENDED state so we only do this if really necessary. */
|
process in SUSPENDED state so we only do this if really necessary. */
|
||||||
if (!GetHandleInformation ((HANDLE) sock, &flags)
|
if (!GetHandleInformation ((HANDLE) sock, &hdl_flags)
|
||||||
|| !(flags & HANDLE_FLAG_INHERIT))
|
|| !(hdl_flags & HANDLE_FLAG_INHERIT))
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
SOCKET base_sock;
|
SOCKET base_sock;
|
||||||
@ -303,7 +303,7 @@ fhandler_socket::set_socket_handle (SOCKET sock)
|
|||||||
debug_printf ("WSAIoctl: %u", WSAGetLastError ());
|
debug_printf ("WSAIoctl: %u", WSAGetLastError ());
|
||||||
else if (base_sock != sock)
|
else if (base_sock != sock)
|
||||||
{
|
{
|
||||||
if (GetHandleInformation ((HANDLE) base_sock, &flags)
|
if (GetHandleInformation ((HANDLE) base_sock, &hdl_flags)
|
||||||
&& (flags & HANDLE_FLAG_INHERIT))
|
&& (flags & HANDLE_FLAG_INHERIT))
|
||||||
{
|
{
|
||||||
if (!DuplicateHandle (GetCurrentProcess (), (HANDLE) base_sock,
|
if (!DuplicateHandle (GetCurrentProcess (), (HANDLE) base_sock,
|
||||||
@ -312,19 +312,22 @@ fhandler_socket::set_socket_handle (SOCKET sock)
|
|||||||
debug_printf ("DuplicateHandle failed, %E");
|
debug_printf ("DuplicateHandle failed, %E");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
closesocket (sock);
|
::closesocket (sock);
|
||||||
sock = base_sock;
|
sock = base_sock;
|
||||||
lsp_fixup = false;
|
lsp_fixup = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
set_addr_family (af);
|
||||||
|
set_socket_type (type);
|
||||||
|
if (flags & SOCK_NONBLOCK)
|
||||||
|
set_nonblocking (true);
|
||||||
|
if (flags & SOCK_CLOEXEC)
|
||||||
|
set_close_on_exec (true);
|
||||||
set_io_handle ((HANDLE) sock);
|
set_io_handle ((HANDLE) sock);
|
||||||
if (!init_events ())
|
if (!init_events ())
|
||||||
{
|
return -1;
|
||||||
closesocket (sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (lsp_fixup)
|
if (lsp_fixup)
|
||||||
init_fixup_before ();
|
init_fixup_before ();
|
||||||
set_flags (O_RDWR | O_BINARY);
|
set_flags (O_RDWR | O_BINARY);
|
||||||
@ -360,6 +363,7 @@ int
|
|||||||
fhandler_socket::socket (int af, int type, int protocol, int flags)
|
fhandler_socket::socket (int af, int type, int protocol, int flags)
|
||||||
{
|
{
|
||||||
SOCKET sock;
|
SOCKET sock;
|
||||||
|
int ret;
|
||||||
|
|
||||||
sock = ::socket (af == AF_LOCAL ? AF_INET : af, type, protocol);
|
sock = ::socket (af == AF_LOCAL ? AF_INET : af, type, protocol);
|
||||||
if (sock == INVALID_SOCKET)
|
if (sock == INVALID_SOCKET)
|
||||||
@ -367,13 +371,12 @@ fhandler_socket::socket (int af, int type, int protocol, int flags)
|
|||||||
set_winsock_errno ();
|
set_winsock_errno ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
set_addr_family (af);
|
ret = set_socket_handle (sock, af, type, flags);
|
||||||
set_socket_type (type);
|
if (ret < 0)
|
||||||
if (flags & SOCK_NONBLOCK)
|
::closesocket (sock);
|
||||||
set_nonblocking (true);
|
return ret;
|
||||||
if (flags & SOCK_CLOEXEC)
|
}
|
||||||
set_close_on_exec (true);
|
|
||||||
return set_socket_handle (sock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user