4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-30 19:10:36 +08:00

* fhandler_socket.cc (fhandler_socket::signal_secret_event): New

function.
* fhandler.h: Declare it.
* fhandler_socket.cc (fhandler_socket::create_secret_event): Don't
signal secret event immediately.
(fhandler_socket::check_peer_secret_event): Do it after peer event
was opened.
* net.cc (cygwin_connect): Or if socket is non-blocking.
(cygwin_accept): Ditto.
This commit is contained in:
Egor Duda 2001-06-20 06:50:13 +00:00
parent 4abaaac33c
commit ae036f47c5
4 changed files with 44 additions and 15 deletions

View File

@ -1,3 +1,15 @@
2001-06-20 Egor Duda <deo@logos-m.ru>
* fhandler_socket.cc (fhandler_socket::signal_secret_event): New
function.
* fhandler.h: Declare it.
* fhandler_socket.cc (fhandler_socket::create_secret_event): Don't
signal secret event immediately.
(fhandler_socket::check_peer_secret_event): Do it after peer event
was opened.
* net.cc (cygwin_connect): Or if socket is non-blocking.
(cygwin_accept): Ditto.
Mon Jun 18 17:09:25 2001 Christopher Faylor <cgf@cygnus.com> Mon Jun 18 17:09:25 2001 Christopher Faylor <cgf@cygnus.com>
* fhandler_tty.cc (fhandler_tty_slave::init): Revert 2001-06-16 change. * fhandler_tty.cc (fhandler_tty_slave::init): Revert 2001-06-16 change.

View File

@ -397,6 +397,7 @@ public:
void get_connect_secret (char*); void get_connect_secret (char*);
HANDLE create_secret_event (int *secret = NULL); HANDLE create_secret_event (int *secret = NULL);
int check_peer_secret_event (struct sockaddr_in *peer, int *secret = NULL); int check_peer_secret_event (struct sockaddr_in *peer, int *secret = NULL);
void signal_secret_event ();
void close_secret_event (); void close_secret_event ();
}; };

View File

@ -103,14 +103,18 @@ fhandler_socket::create_secret_event (int* secret)
secret_event = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf); secret_event = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf);
if (secret_event) if (secret_event)
{ ProtectHandle (secret_event);
ProtectHandle (secret_event);
SetEvent (secret_event);
}
return secret_event; return secret_event;
} }
void
fhandler_socket::signal_secret_event ()
{
if (secret_event)
SetEvent (secret_event);
}
void void
fhandler_socket::close_secret_event () fhandler_socket::close_secret_event ()
{ {
@ -136,6 +140,8 @@ fhandler_socket::check_peer_secret_event (struct sockaddr_in* peer, int* secret)
ev = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf); ev = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf);
} }
signal_secret_event ();
if (ev) if (ev)
{ {
DWORD rc = WaitForSingleObject (ev, 10000); DWORD rc = WaitForSingleObject (ev, 10000);

View File

@ -739,6 +739,7 @@ cygwin_connect (int fd,
{ {
int res; int res;
BOOL secret_check_failed = FALSE; BOOL secret_check_failed = FALSE;
BOOL in_progress = FALSE;
fhandler_socket *sock = get (fd); fhandler_socket *sock = get (fd);
sockaddr_in sin; sockaddr_in sin;
int secret [4]; int secret [4];
@ -759,18 +760,23 @@ cygwin_connect (int fd,
/* Special handling for connect to return the correct error code /* Special handling for connect to return the correct error code
when called to early on a non-blocking socket. */ when called to early on a non-blocking socket. */
if (WSAGetLastError () == WSAEWOULDBLOCK) if (WSAGetLastError () == WSAEWOULDBLOCK)
WSASetLastError (WSAEINPROGRESS); {
WSASetLastError (WSAEINPROGRESS);
in_progress = TRUE;
}
set_winsock_errno (); set_winsock_errno ();
} }
if (sock->get_addr_family () == AF_UNIX) if (sock->get_addr_family () == AF_UNIX)
{ {
if (!res || errno == EINPROGRESS) if (!res || in_progress)
{ {
if (!sock->create_secret_event (secret)) if (!sock->create_secret_event (secret))
{ {
secret_check_failed = TRUE; secret_check_failed = TRUE;
} }
else if (in_progress)
sock->signal_secret_event ();
} }
if (!secret_check_failed && !res) if (!secret_check_failed && !res)
@ -887,6 +893,7 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len)
{ {
int res = -1; int res = -1;
BOOL secret_check_failed = FALSE; BOOL secret_check_failed = FALSE;
BOOL in_progress = FALSE;
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
fhandler_socket *sock = get (fd); fhandler_socket *sock = get (fd);
@ -901,18 +908,21 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len)
res = accept (sock->get_socket (), peer, len); // can't use a blocking call inside a lock res = accept (sock->get_socket (), peer, len); // can't use a blocking call inside a lock
if ((SOCKET) res == (SOCKET) INVALID_SOCKET &&
WSAGetLastError () == WSAEWOULDBLOCK)
in_progress = TRUE;
if (sock->get_addr_family () == AF_UNIX) if (sock->get_addr_family () == AF_UNIX)
{ {
if (((SOCKET) res != (SOCKET) INVALID_SOCKET || if ((SOCKET) res != (SOCKET) INVALID_SOCKET || in_progress)
WSAGetLastError () == WSAEWOULDBLOCK)) {
{ if (!sock->create_secret_event ())
if (!sock->create_secret_event ()) secret_check_failed = TRUE;
{ else if (in_progress)
secret_check_failed = TRUE; sock->signal_secret_event ();
} }
}
if (!secret_check_failed && if (!secret_check_failed &&
(SOCKET) res != (SOCKET) INVALID_SOCKET) (SOCKET) res != (SOCKET) INVALID_SOCKET)
{ {
if (!sock->check_peer_secret_event ((struct sockaddr_in*) peer)) if (!sock->check_peer_secret_event ((struct sockaddr_in*) peer))