[Mono-bugs] [Bug 74161][Nor] New - XmlTextReader.Read blocked when reading Xml from Network Stream

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Mon, 28 Mar 2005 19:11:32 -0500 (EST)


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 anarchyco@hotmail.com.

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

--- shadow/74161	2005-03-28 19:11:32.000000000 -0500
+++ shadow/74161.tmp.25534	2005-03-28 19:11:32.000000000 -0500
@@ -0,0 +1,85 @@
+Bug#: 74161
+Product: Mono: Class Libraries
+Version: unspecified
+OS: SUSE 9.2
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.XML
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: anarchyco@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: XmlTextReader.Read blocked when reading Xml from Network Stream
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+Different behavior in XmlTextReader between Mono and MS.NET when reading
+from a network stream (a jabber server for example). Mono is blocked in the
+first XmlTextReader.Read ().
+
+Steps to reproduce the problem:
+
+TcpClient client = new TcpClient("jabber.org",5222);
+
+client.GetStream().Write(Encoding.UTF8.GetBytes("<stream:stream
+to='jabber.org' xmlns='jabber:client'
+xmlns:stream='http://etherx.jabber.org/streams'>"));
+
+client.GetStream().Flush ();
+
+XmlTextReader reader = new XmpTextReader (client.GetStream());
+
+while (reader.Read()) // Never returns in Mono 
+{
+     Console.WriteLine ("Read node");
+}
+
+
+Actual Results:
+Mono is blocked in reader.Read().  MS.NET is not blocked and allows the
+reading of the first node.
+
+Expected Results:
+The same as MS.NET.
+
+How often does this happen? 
+Always.
+
+
+Additional Information:
+I think the problem is between XmlInputStream.Read and StreamReader.Read.
+When you have buffered X bytes (<1024) and XmlTextReader calls Read 
+(1024) both methods don't return until they have read 1024 bytes.  
+I've modified the code and now works as MS .NET but I think my changes 
+could have secondary effects.
+
+** StreamReader.cs  Ln 362  Comment loop
+
+//while (count > 0)
+
+** XmlInputStream.cs Ln 270 Modified Read Method
+
+public override int Read (byte[] buffer, int offset, int count) {
+        int ret;
+
+        if (count <= bufLength - bufPos) { // all from buffer
+            Array.Copy (this.buffer, bufPos, buffer, offset, count);
+            bufPos += count;
+            ret = count;
+        } else if (bufLength==bufPos) {
+            ret = stream.Read (buffer,offset,count);
+        } else {
+            int bufRest = bufLength - bufPos;
+            if (bufLength > bufPos) {
+          Array.Copy (this.buffer, bufPos, buffer, offset, bufRest);
+                bufPos += bufRest;
+      }
+    ret = bufRest; //stream.Read (buffer, offset + bufRest, count -
+bufRest); } return ret; }