[Mono-bugs] [Bug 63233][Wis] New - Async read does not receive socket exception, on disconnect

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 17 Aug 2004 12:14:27 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by jeroen@asselman.com.

http://bugzilla.ximian.com/show_bug.cgi?id=63233

--- shadow/63233	2004-08-17 12:14:27.000000000 -0400
+++ shadow/63233.tmp.6169	2004-08-17 12:14:27.000000000 -0400
@@ -0,0 +1,103 @@
+Bug#: 63233
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: Gentoo linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: jeroen@asselman.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Async read does not receive socket exception, on disconnect
+
+An AsyncRead does not receive a socketexception when the connection got closed.
+
+This happens for example with the following testcase. (I'll attach it as a
+seperate attachment later). Expected is a webserver at localhost port 80.
+
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+
+namespace Asselman
+{
+        /// <summary>
+        /// Summary description for Class1.
+        /// </summary>
+        class TestCaseAsyncNetworkStream
+        {
+                /// <summary>
+                /// The main entry point for the application.
+                /// </summary>
+                [STAThread]
+                static void Main(string[] args)
+                {
+                        TestCaseAsyncNetworkStream test = new
+TestCaseAsyncNetworkStream();
+                        IPEndPoint destination = new
+IPEndPoint(IPAddress.Parse("127.0.0.1"), 80);
+                        test.Connect(destination);
+                }
+
+                public void Connect(IPEndPoint destination)
+                {
+                        m_tcpClient = new TcpClient();
+                        m_tcpClient.Connect(destination);
+                        m_tcpStream = m_tcpClient.GetStream();
+                        m_smallBuffer = new byte[1];
+                        m_readCallback = new AsyncCallback(ReadCallBack);
+
+                        string hello = "GET /InvalidUrlIHope HTTP/1.0\r\n\r\n";
+                        byte[] hellobuf =
+System.Text.ASCIIEncoding.ASCII.GetBytes(hello);
+                        m_tcpStream.BeginWrite(hellobuf, 0,
+hellobuf.Length, null, this);
+                        m_tcpStream.BeginRead(m_smallBuffer,0,
+m_smallBuffer.Length, m_readCallback, this);
+                        Console.ReadLine();
+                }
+
+                public void ReadCallBack(IAsyncResult result)
+                {
+                        int bytesRead = m_tcpStream.EndRead(result);
+
+
+                        if (bytesRead == 0)
+                        {
+                                m_tcpStream.Close();
+                                m_tcpClient.Close();
+                                Console.WriteLine("End of stream");
+                                return; // Connection closed
+                        }
+
+                        Console.Write((char) m_smallBuffer[0]);
+
+                        // Be slow
+                        System.Threading.Thread.Sleep(100);
+
+                        m_tcpStream.BeginRead(m_smallBuffer,0,
+m_smallBuffer.Length, m_readCallback, this);
+                }
+
+                private TcpClient m_tcpClient;
+                private Stream m_tcpStream;
+                private byte[] m_smallBuffer;
+                private AsyncCallback m_readCallback;
+        }
+}
+
+Actual Results:
+It never receives a SocketException or bytesread == 0 is never reached.
+
+Expected Results:
+On windows with .net framework 1.1 I get an socketexception
+
+How often does this happen? 
+Always