From d510072c834371e39bcf61e0d6e9128562eb8a34 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 16 Jun 2014 13:01:40 +0000 Subject: [PATCH] * fhandler_socket.cc (fhandler_socket::evaluate_events): Call WSASetLastError after setsockopt. Explain why. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/fhandler_socket.cc | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0955ce1a0..de2ed2e5a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2014-06-16 Corinna Vinschen + + * fhandler_socket.cc (fhandler_socket::evaluate_events): Call + WSASetLastError after setsockopt. Explain why. + 2014-06-16 Denis Excoffier * grp.cc (getgrouplist): Fix setting ngroups to make sure to return diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index d4602be8a..2c3c75c91 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -633,7 +633,6 @@ fhandler_socket::evaluate_events (const long event_mask, long &events, int wsa_err = 0; if ((wsa_err = wsock_events->connect_errorcode) != 0) { - WSASetLastError (wsa_err); /* CV 2014-04-23: This is really weird. If you call connect asynchronously on a socket and then select, an error like "Connection refused" is set in the event and in the SO_ERROR @@ -642,9 +641,14 @@ fhandler_socket::evaluate_events (const long event_mask, long &events, option, even if the dup'ed socket handle refers to the same socket. We're trying to workaround this problem here by taking the connect errorcode from the event and write it back - into the SO_ERROR socket option. */ + into the SO_ERROR socket option. + + CV 2014-06-16: Call WSASetLastError *after* setsockopt since, + apparently, setsockopt sets the last WSA error code to 0 on + success. */ setsockopt (get_socket (), SOL_SOCKET, SO_ERROR, (const char *) &wsa_err, sizeof wsa_err); + WSASetLastError (wsa_err); ret = SOCKET_ERROR; } else