diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2004-04-01 13:48:15 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2004-04-01 13:48:15 +0400 |
commit | 54aefcc6bc3422afd8b59b000202e17bf3baab2d (patch) | |
tree | 254fb88542f1ad45a9a92c66c95f6adc3020dbc5 | |
parent | fbba4780afa4e15effff7ae122252cbf919ac77e (diff) |
* fhandler_socket.cc (fhandler_socket::sendto): Drop out of loop if
has_been_closed gets set.
(fhandler_socket::sendmsg): Ditto.
* net.cc (wsock_event::wait): Don't initialize evts. Don't try to
evaluate network events if WSAEnumNetworkEvents fails.
(wsock_event::release): Save last WSA error and set it again unless
resetting to blocking socket fails.
* wsock_event.h (class wsock_event): Remove destructor.
-rw-r--r-- | winsup/cygwin/ChangeLog | 11 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_socket.cc | 6 | ||||
-rw-r--r-- | winsup/cygwin/net.cc | 55 | ||||
-rw-r--r-- | winsup/cygwin/wsock_event.h | 6 |
4 files changed, 45 insertions, 33 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d2bcb1b90..e60be8d38 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2004-04-01 Corinna Vinschen <corinna@vinschen.de> + + * fhandler_socket.cc (fhandler_socket::sendto): Drop out of loop if + has_been_closed gets set. + (fhandler_socket::sendmsg): Ditto. + * net.cc (wsock_event::wait): Don't initialize evts. Don't try to + evaluate network events if WSAEnumNetworkEvents fails. + (wsock_event::release): Save last WSA error and set it again unless + resetting to blocking socket fails. + * wsock_event.h (class wsock_event): Remove destructor. + 2004-03-31 Corinna Vinschen <corinna@vinschen.de> * fhandler_tape.cc (mtinfo::initialize): Fix fatal error message. diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index 952b87b82..878880da0 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -953,7 +953,8 @@ fhandler_socket::sendto (const void *ptr, size_t len, int flags, break; } } - while (!(res = wsock_evt.wait (get_socket (), has_been_closed))); + while (!(res = wsock_evt.wait (get_socket (), has_been_closed)) + && !has_been_closed); wsock_evt.release (get_socket ()); } } @@ -1088,7 +1089,8 @@ fhandler_socket::sendmsg (const struct msghdr *msg, int flags, ssize_t tot) break; } } - while (!(res = wsock_evt.wait (get_socket (), has_been_closed))); + while (!(res = wsock_evt.wait (get_socket (), has_been_closed)) + && !has_been_closed); wsock_evt.release (get_socket ()); } } diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 0bdff32e3..2459580b5 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -75,32 +75,33 @@ wsock_event::wait (int sock, int &closed) { case WSA_WAIT_EVENT_0: WSANETWORKEVENTS evts; - memset (&evts, 0, sizeof evts); - WSAEnumNetworkEvents (sock, event, &evts); - if (evts.lNetworkEvents & FD_READ) + if (!WSAEnumNetworkEvents (sock, event, &evts)) { - 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 && evts.iErrorCode[FD_CLOSE_BIT]) - wsa_err = evts.iErrorCode[FD_CLOSE_BIT]; - else - ret = 0; + 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 && evts.iErrorCode[FD_CLOSE_BIT]) + wsa_err = evts.iErrorCode[FD_CLOSE_BIT]; + else + ret = 0; + } + if (wsa_err) + WSASetLastError (wsa_err); } - if (wsa_err) - WSASetLastError (wsa_err); break; case WSA_WAIT_EVENT_0 + 1: WSASetLastError (WSAEINTR); @@ -114,10 +115,14 @@ wsock_event::wait (int sock, int &closed) void wsock_event::release (int sock) { + int last_err = WSAGetLastError (); WSAEventSelect (sock, event, 0); WSACloseEvent (event); unsigned long non_block = 0; - ioctlsocket (sock, FIONBIO, &non_block); + if (ioctlsocket (sock, FIONBIO, &non_block)) + debug_printf ("return to blocking failed: %d", WSAGetLastError ()); + else + WSASetLastError (last_err); } WSADATA wsadata; diff --git a/winsup/cygwin/wsock_event.h b/winsup/cygwin/wsock_event.h index 9a1f07ac1..5383a797b 100644 --- a/winsup/cygwin/wsock_event.h +++ b/winsup/cygwin/wsock_event.h @@ -16,12 +16,6 @@ class wsock_event WSAEVENT event; public: wsock_event () : event (NULL) {}; - ~wsock_event () - { - if (event) - WSACloseEvent (event); - event = NULL; - }; /* The methods are implemented in net.cc */ bool prepare (int sock, long event_mask); |