Revert patches from 2005-10-22 and 2006-06-14 to use event driven
accept and connect back to using select: * fhandler.h (class fhandler_socket): Remove accept_mtx. * fhandler_socket.cc (fhandler_socket::fhandler_socket): Drop initializing accept_mtx. (fhandler_socket::accept): Drop event handling. (fhandler_socket.cc (fhandler_socket::connect): Ditto. (fhandler_socket::dup): Drop accept_mtx handling. (fhandler_socket::listen): Ditto. (fhandler_socket::prepare): Ditto. (fhandler_socket::release): Ditto. (fhandler_socket::close): Ditto. * net.cc (cygwin_accept): Revert to calling cygwin_select to implement interuptible accept. (cygwin_connect): Ditto for connect.
This commit is contained in:
@ -127,7 +127,6 @@ get_inet_addr (const struct sockaddr *in, int inlen,
|
||||
|
||||
fhandler_socket::fhandler_socket () :
|
||||
fhandler_base (),
|
||||
accept_mtx (NULL),
|
||||
sun_path (NULL),
|
||||
status ()
|
||||
{
|
||||
@ -454,7 +453,6 @@ fhandler_socket::dup (fhandler_base *child)
|
||||
|
||||
debug_printf ("here");
|
||||
fhandler_socket *fhs = (fhandler_socket *) child;
|
||||
fhs->accept_mtx = NULL;
|
||||
fhs->addr_family = addr_family;
|
||||
fhs->set_socket_type (get_socket_type ());
|
||||
if (get_addr_family () == AF_LOCAL)
|
||||
@ -471,17 +469,6 @@ fhandler_socket::dup (fhandler_base *child)
|
||||
}
|
||||
}
|
||||
fhs->connect_state (connect_state ());
|
||||
if (accept_mtx)
|
||||
{
|
||||
if (!DuplicateHandle (hMainProc, accept_mtx, hMainProc, &nh, 0,
|
||||
TRUE, DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
system_printf ("DuplicateHandle(%x) failed, %E", accept_mtx);
|
||||
__seterrno ();
|
||||
return -1;
|
||||
}
|
||||
fhs->accept_mtx = nh;
|
||||
}
|
||||
|
||||
/* Since WSADuplicateSocket() fails on NT systems when the process
|
||||
is currently impersonating a non-privileged account, we revert
|
||||
@ -512,10 +499,8 @@ fhandler_socket::dup (fhandler_base *child)
|
||||
if (!DuplicateHandle (hMainProc, get_io_handle (), hMainProc, &nh, 0,
|
||||
FALSE, DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
system_printf ("DuplicateHandle(%x) failed, %E", get_io_handle ());
|
||||
system_printf ("!DuplicateHandle(%x) failed, %E", get_io_handle ());
|
||||
__seterrno ();
|
||||
if (fhs->accept_mtx)
|
||||
CloseHandle (fhs->accept_mtx);
|
||||
return -1;
|
||||
}
|
||||
VerifyHandle (nh);
|
||||
@ -768,20 +753,7 @@ fhandler_socket::connect (const struct sockaddr *name, int namelen)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_nonblocking ())
|
||||
res = ::connect (get_socket (), (struct sockaddr *) &sin, namelen);
|
||||
else
|
||||
{
|
||||
HANDLE evt;
|
||||
if (prepare (evt, FD_CONNECT))
|
||||
{
|
||||
res = ::connect (get_socket (), (struct sockaddr *) &sin, namelen);
|
||||
if (res == SOCKET_ERROR
|
||||
&& WSAGetLastError () == WSAEWOULDBLOCK)
|
||||
res = wait (evt, 0, INFINITE);
|
||||
release (evt);
|
||||
}
|
||||
}
|
||||
res = ::connect (get_socket (), (struct sockaddr *) &sin, namelen);
|
||||
|
||||
if (!res)
|
||||
err = 0;
|
||||
@ -831,11 +803,6 @@ fhandler_socket::connect (const struct sockaddr *name, int namelen)
|
||||
int
|
||||
fhandler_socket::listen (int backlog)
|
||||
{
|
||||
if (!accept_mtx && !(accept_mtx = CreateMutex (&sec_all, FALSE, NULL)))
|
||||
{
|
||||
set_errno (ENOBUFS);
|
||||
return -1;
|
||||
}
|
||||
int res = ::listen (get_socket (), backlog);
|
||||
if (res)
|
||||
set_winsock_errno ();
|
||||
@ -871,21 +838,7 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
|
||||
if (len && ((unsigned) *len < sizeof (struct sockaddr_in)))
|
||||
*len = sizeof (struct sockaddr_in);
|
||||
|
||||
if (is_nonblocking ())
|
||||
res = ::accept (get_socket (), peer, len);
|
||||
else
|
||||
{
|
||||
HANDLE evt;
|
||||
if (prepare (evt, FD_ACCEPT))
|
||||
{
|
||||
res = wait (evt, 0, INFINITE);
|
||||
if (res != -1
|
||||
|| (WSAGetLastError () != WSAEINTR
|
||||
&& WSAGetLastError () != WSAEFAULT))
|
||||
res = ::accept (get_socket (), peer, len);
|
||||
release (evt);
|
||||
}
|
||||
}
|
||||
res = ::accept (get_socket (), peer, len);
|
||||
|
||||
if (res == (int) INVALID_SOCKET)
|
||||
set_winsock_errno ();
|
||||
@ -980,16 +933,6 @@ fhandler_socket::getpeername (struct sockaddr *name, int *namelen)
|
||||
bool
|
||||
fhandler_socket::prepare (HANDLE &event, long event_mask)
|
||||
{
|
||||
if (event_mask == FD_ACCEPT && accept_mtx)
|
||||
{
|
||||
HANDLE obj[2] = { accept_mtx, signal_arrived };
|
||||
if (WaitForMultipleObjects (2, obj, FALSE, INFINITE) != WAIT_OBJECT_0)
|
||||
{
|
||||
debug_printf ("signal_arrived");
|
||||
WSASetLastError (WSAEINTR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
WSASetLastError (0);
|
||||
closed (false);
|
||||
if ((event = WSACreateEvent ()) == WSA_INVALID_EVENT)
|
||||
@ -1114,8 +1057,6 @@ fhandler_socket::release (HANDLE event)
|
||||
debug_printf ("return to blocking failed: %d", WSAGetLastError ());
|
||||
else
|
||||
WSASetLastError (last_err);
|
||||
if (accept_mtx)
|
||||
ReleaseMutex (accept_mtx);
|
||||
}
|
||||
|
||||
int
|
||||
@ -1488,8 +1429,6 @@ fhandler_socket::close ()
|
||||
}
|
||||
WSASetLastError (0);
|
||||
}
|
||||
if (!res && accept_mtx)
|
||||
CloseHandle (accept_mtx);
|
||||
|
||||
debug_printf ("%d = fhandler_socket::close()", res);
|
||||
return res;
|
||||
|
Reference in New Issue
Block a user