From 321ddf2422d3fafe29c68c2945bcc9063a238d83 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 3 Apr 2004 19:07:59 +0000 Subject: * fhandler.h (class fhandler_socket): Remove has_been_closed member. * fhandler_socket.cc (fhandler_socket::recvfrom): Revert to overlapped I/O. (fhandler_socket::recvmsg): Ditto. (fhandler_socket::sendto): Ditto. (fhandler_socket::sendmsg): Ditto. * net.cc (wsock_event::prepare): Ditto. (wsock_event::wait): Ditto. Evaluate overlapped result also after calling CancelIo (thanks to Patrick Samson ). (wsock_event::release): Remove. * wsock_event.h: Revert to overlapped I/O. --- winsup/cygwin/net.cc | 92 +++++++++++++++++++--------------------------------- 1 file changed, 34 insertions(+), 58 deletions(-) (limited to 'winsup/cygwin/net.cc') diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 32b9f1f3e..c0c5b84c6 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -50,83 +50,59 @@ extern "C" int sscanf (const char *, const char *, ...); } /* End of "C" section */ -bool -wsock_event::prepare (int sock, long event_mask) +LPWSAOVERLAPPED +wsock_event::prepare () { - WSASetLastError (0); - if ((event = WSACreateEvent ()) == WSA_INVALID_EVENT) - debug_printf ("WSACreateEvent: %E"); - else if (WSAEventSelect (sock, event, event_mask) == SOCKET_ERROR) + LPWSAOVERLAPPED ret = NULL; + + SetLastError (0); + if ((event = WSACreateEvent ()) != WSA_INVALID_EVENT) { - debug_printf ("WSAEventSelect: %E"); - WSACloseEvent (event); - event = WSA_INVALID_EVENT; + memset (&ovr, 0, sizeof ovr); + ovr.hEvent = event; + ret = &ovr; } - return event != WSA_INVALID_EVENT; + else if (GetLastError () == ERROR_PROC_NOT_FOUND) /* winsock2 not available */ + WSASetLastError (0); + + debug_printf ("%d = wsock_event::prepare ()", ret); + return ret; } int -wsock_event::wait (int sock, int &closed) +wsock_event::wait (int socket, LPDWORD flags) { int ret = SOCKET_ERROR; - int wsa_err = 0; WSAEVENT ev[2] = { event, signal_arrived }; + DWORD len; + switch (WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE, FALSE)) { case WSA_WAIT_EVENT_0: - WSANETWORKEVENTS evts; - if (!WSAEnumNetworkEvents (sock, event, &evts)) + if (WSAGetOverlappedResult (socket, &ovr, &len, FALSE, flags)) + ret = (int) len; + break; + case WSA_WAIT_EVENT_0 + 1: + if (!CancelIo ((HANDLE) socket)) { - if (evts.lNetworkEvents & FD_READ) - { - if (evts.iErrorCode[FD_READ_BIT]) - wsa_err = evts.iErrorCode[FD_READ_BIT]; - else - ret = 0; - } - else if (evts.lNetworkEvents & FD_WRITE) - { - if (evts.iErrorCode[FD_WRITE_BIT]) - wsa_err = evts.iErrorCode[FD_WRITE_BIT]; - else - ret = 0; - } - if (evts.lNetworkEvents & FD_CLOSE) - { - closed = 1; - if (!wsa_err) - { - if (evts.iErrorCode[FD_CLOSE_BIT]) - wsa_err = evts.iErrorCode[FD_CLOSE_BIT]; - else - ret = 0; - } - } - if (wsa_err) - WSASetLastError (wsa_err); + debug_printf ("CancelIo() %E, fallback to blocking io"); + WSAGetOverlappedResult (socket, &ovr, &len, TRUE, flags); } + else if (WSAGetOverlappedResult (socket, &ovr, &len, FALSE, flags) + && len > 0) + ret = (int) len; + else + WSASetLastError (WSAEINTR); break; - case WSA_WAIT_EVENT_0 + 1: - WSASetLastError (WSAEINTR); + case WSA_WAIT_FAILED: break; - default: + default: /* Should be impossible. *LOL* */ WSASetLastError (WSAEFAULT); + break; } - return ret; -} - -void -wsock_event::release (int sock) -{ - int last_err = WSAGetLastError (); - /* KB 168349: NT4 fails if the event parameter is not NULL. */ - WSAEventSelect (sock, NULL, 0); WSACloseEvent (event); - unsigned long non_block = 0; - if (ioctlsocket (sock, FIONBIO, &non_block)) - debug_printf ("return to blocking failed: %d", WSAGetLastError ()); - else - WSASetLastError (last_err); + event = NULL; + return ret; } WSADATA wsadata; -- cgit v1.2.3