2007-01-26 Dick Porter <dick@ximian.com>
authorDick Porter <dick@acm.org>
Fri, 26 Jan 2007 14:27:47 +0000 (14:27 -0000)
committerDick Porter <dick@acm.org>
Fri, 26 Jan 2007 14:27:47 +0000 (14:27 -0000)
* Socket.cs: There's no point checking the SO_ERROR status of a
socket after poll() or select() if we already know that connected
== true.

2007-01-26  Dick Porter  <dick@ximian.com>

* SocketTest.cs: New test for SO_ERROR reading, returning the same
value over and over.

svn path=/trunk/mcs/; revision=71751

mcs/class/System/System.Net.Sockets/ChangeLog
mcs/class/System/System.Net.Sockets/Socket.cs
mcs/class/System/Test/System.Net.Sockets/ChangeLog
mcs/class/System/Test/System.Net.Sockets/SocketTest.cs

index 1fbabb5610eae7fd3550f31704e9c214a3e7c704..36265c384fa0a2829603a089f04db61c861e5946 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-26  Dick Porter  <dick@ximian.com>
+
+       * Socket.cs: There's no point checking the SO_ERROR status of a
+       socket after poll() or select() if we already know that connected
+       == true.
+
 2007-01-24  Dick Porter  <dick@ximian.com>
 
        * IOControlCode.cs: 
index 3e06e1e0518c9b508fae160d93fd6a1c5eca09e4..c858710d0e7484f35d4616355538964261f4830d 100644 (file)
@@ -415,8 +415,8 @@ namespace System.Net.Sockets
                                                }
 
                                                if (!result.Sock.Blocking) {
-                                                       result.Sock.Poll (-1, SelectMode.SelectWrite);
-                                                       int success = (int)result.Sock.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error);
+                                                       int success;
+                                                       result.Sock.Poll (-1, SelectMode.SelectWrite, out success);
                                                        if (success == 0) {
                                                                result.Sock.connected = true;
                                                                result.Complete ();
@@ -631,7 +631,8 @@ namespace System.Net.Sockets
                                }
 
                                if (currentList != null) {
-                                       if (currentList == checkWrite) {
+                                       if (currentList == checkWrite &&
+                                           sock.connected == false) {
                                                if ((int)sock.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error) == 0) {
                                                        sock.connected = true;
                                                }
@@ -2477,7 +2478,9 @@ namespace System.Net.Sockets
                        if (error != 0)
                                throw new SocketException (error);
 
-                       if (mode == SelectMode.SelectWrite && result == true) {
+                       if (mode == SelectMode.SelectWrite &&
+                           result == true &&
+                           connected == false) {
                                /* Update the connected state; for
                                 * non-blocking Connect()s this is
                                 * when we can find out that the
index c702adb864886fe526ce6483499f6ed0f84032d7..c267d07cef743f56be6b2097439a6cfdf3d7e991 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-26  Dick Porter  <dick@ximian.com>
+
+       * SocketTest.cs: New test for SO_ERROR reading, returning the same
+       value over and over.
+
 2007-01-25  Ilya Kharmatsky <ilyak -at- mainsoft.com>
 
        * UdbClientTest.cs: Added Ignore attribute for entire test fixture
index 5f836f67ecfbe0e87e0ea8146b14bed2a2fd2e66..bbb2b3763178bf5afe91af09b2e122e50c5a48c5 100644 (file)
@@ -502,6 +502,55 @@ namespace MonoTests.System.Net.Sockets
                        s.Shutdown (0);
                }
 
+               static ManualResetEvent SocketError_event = new ManualResetEvent (false);
+
+               private static void SocketError_callback (IAsyncResult ar)
+               {
+                       Socket sock = (Socket)ar.AsyncState;
+                       
+                       if(sock.Connected) {
+                               sock.EndConnect (ar);
+                       }
+
+                       SocketError_event.Set ();
+               }
+
+               [Test]
+               public void SocketError ()
+               {
+                       Socket sock = new Socket (AddressFamily.InterNetwork,
+                                                 SocketType.Stream,
+                                                 ProtocolType.Tcp);
+                       IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
+                                                       BogusPort);
+                       
+                       SocketError_event.Reset ();
+
+                       sock.Blocking = false;
+                       sock.BeginConnect (ep, SocketError_callback,
+                                          sock);
+
+                       if (SocketError_event.WaitOne (2000, false) == false) {
+                               Assert.Fail ("SocketError wait timed out");
+                       }
+
+                       Assertion.AssertEquals ("SocketError #1", false,
+                                               sock.Connected);
+
+                       int error;
+
+                       error = (int)sock.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error);
+                       Assertion.AssertEquals ("SocketError #2", 10061,
+                                               error);
+
+                       error = (int)sock.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error);
+                       Assertion.AssertEquals ("SocketError #3", 10061,
+                                               error);
+
+                       sock.Close ();
+               }
+               
+
 #if NET_2_0
                [Test]
                public void SocketInformationCtor ()