[Mono-bugs] [Bug 591291] XmlInputStream.Read may block with unprocessed bytes in buffer

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Mar 27 20:33:25 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=591291

http://bugzilla.novell.com/show_bug.cgi?id=591291#c2


Mark Apperson <mapperso at cisco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW
       InfoProvider|mapperso at cisco.com          |

--- Comment #2 from Mark Apperson <mapperso at cisco.com> 2010-03-28 00:33:24 UTC ---
OK, try this piece of code.  The Sleep is necessary to give the first bits of
data a chance to move through the streams/socket before the XmlReader is
initialized.


using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Xml;

namespace XmlReaderDeadlock
{
    class MainClass
    {
        static Byte[] rootBytes = Encoding.ASCII.GetBytes("<ROOT>");
        static Byte[] tagBytes = Encoding.ASCII.GetBytes("<TAG>value</TAG>");
        static NetworkStream serverStream;

        static void Main(string[] args)
        {
            Int32 ctr = 0;
            new Thread(ServerImpl).Start();
            TcpClient client = new TcpClient();
            client.Connect("localhost", 8080);
        Thread.Sleep(100);

            XmlReader reader = XmlReader.Create(client.GetStream());
            while (reader.Read())
            {
                switch (reader.Name)
                {
                    case "TAG":
                        ++ctr;
                        //Int64 position = serverStream.Position;
                        Console.WriteLine("Read Tag");
                        serverStream.Write(tagBytes, 0, tagBytes.Length);
                        //serverStream.Position = position;
                        break;
                    default:
                        break;
                }

                if (ctr >= 10) break;
            }

            Console.WriteLine("Done");
        }

        public static void ServerImpl()
        {
            TcpListener listener = new TcpListener(System.Net.IPAddress.Any,
8080);
            listener.Start();
            Socket svrSocket = listener.AcceptSocket();
            serverStream = new NetworkStream(svrSocket);
            serverStream.Write(rootBytes, 0, rootBytes.Length);
            serverStream.Write(tagBytes, 0, tagBytes.Length);
        }
    }
}

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list