+2006-06-14 Corinna Vinschen <corinna@vinschen.de>
+
+ * fhandler.h (class fhandler_socket): Add private mutex handle
+ accept_mtx.
+ * fhandler_socket.cc (fhandler_socket::fhandler_socket): Initialize
+ accept_mtx to NULL.
+ (fhandler_socket::dup): Duplicate accept_mtx, if available.
+ (fhandler_socket::listen): Create accept_mtx before trying to listen.
+ (fhandler_socket::prepare): Wait for accept_mtx if available to
+ serialize accepts on the same socket.
+ (fhandler_socket::release): Release accept_mtx.
+ (fhandler_socket::close): Close accept_mtx on successful closesocket.
+
2006-06-12 Christopher Faylor <cgf@timesys.com>
* fhandler_tty.cc (fhandler_pty_master::close): Always close
fhandler_socket::fhandler_socket () :
fhandler_base (),
+ accept_mtx (NULL),
sun_path (NULL),
status ()
{
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)
}
}
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
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);
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 ();
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)
debug_printf ("return to blocking failed: %d", WSAGetLastError ());
else
WSASetLastError (last_err);
+ if (accept_mtx)
+ ReleaseMutex (accept_mtx);
}
int
}
WSASetLastError (0);
}
+ if (!res && accept_mtx)
+ CloseHandle (accept_mtx);
debug_printf ("%d = fhandler_socket::close()", res);
return res;