From 35e8bb2b7eb7cdef63a70a9edea6762ba9560d63 Mon Sep 17 00:00:00 2001
From: Corinna Vinschen <corinna@vinschen.de>
Date: Fri, 2 Sep 2011 09:52:08 +0000
Subject: [PATCH] 	* net.cc (cygwin_getsockopt): Drop erroneous double
 conversion of error 	code returned by SOL_SOCKET/SO_ERROR.  Fix error
 handling.

---
 winsup/cygwin/ChangeLog |  5 +++++
 winsup/cygwin/net.cc    | 15 +++------------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index b0c4656fd..6aaaa7cb4 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,8 @@
+2011-09-02  Corinna Vinschen  <corinna@vinschen.de>
+
+	* net.cc (cygwin_getsockopt): Drop erroneous double conversion of error
+	code returned by SOL_SOCKET/SO_ERROR.  Fix error handling.
+
 2011-09-01  Corinna Vinschen  <corinna@vinschen.de>
 
 	* lc_msg.h: Regenerate.
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 6b63f4b0d..e55dd03ed 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -844,8 +844,9 @@ cygwin_getsockopt (int fd, int level, int optname, void *optval,
 	optname = convert_ws1_ip_optname (optname);
       res = getsockopt (fh->get_socket (), level, optname, (char *) optval,
 			(int *) optlen);
-
-      if (level == SOL_SOCKET)
+      if (res == SOCKET_ERROR)
+	set_winsock_errno ();
+      else if (level == SOL_SOCKET)
 	{
 	  switch (optname)
 	    {
@@ -873,16 +874,6 @@ cygwin_getsockopt (int fd, int level, int optname, void *optval,
 	      break;
 	    }
 	}
-      if (optname == SO_ERROR)
-	{
-	  int *e = (int *) optval;
-
-	  debug_printf ("WinSock SO_ERROR = %d", *e);
-	  *e = find_winsock_errno (*e);
-	}
-
-      if (res)
-	set_winsock_errno ();
     }
 
   syscall_printf ("%d = getsockopt (%d, %d, 0x%x, %p, %p)",