[Mono-list] Stream Issue with WebResponse
Sean Newton
snewton@circadence.com
Mon, 31 Mar 2003 17:02:51 -0700
I'm rather new to Mono and not exactly a linux guru so my issue may not =
be a bug but instead user error. Basically, trying to build a test =
harness for getting performance metrics of web requests. Wrote the code =
on windows, hoping Mono would be a viable alternative for end users that =
wanted to use Linux. Initially structured with a multi-threaded, =
asynchronous design, all worked well under windows but seemed to hang on =
linux/mono, eventually reporting an exception.
Since then, I've simplified the code greatly to isolate the error:
using System;
using System.IO;
using System.Text;
using System.Net;
class Harness {
static void Main(string[] args) {
string url =3D "http://www.microsoft.com";
Console.WriteLine("Creating WebRequest...");
WebRequest request =3D WebRequest.Create(url);
Console.WriteLine("Retrieving WebResponse...");
WebResponse response =3D request.GetResponse();
StreamReader sr =3D new StreamReader(response.GetResponseStream(), =
Encoding.ASCII);
string line =3D null;
Console.WriteLine("Retrieving Stream...");
while( (line =3D sr.ReadLine()) !=3D null) {
Console.WriteLine(line);
}
Console.WriteLine("I never reach this point");
sr.Close();
}
}
While simplifying, I initially tried using using a TextReader and =
ReadToEnd(). That, too, seemed to just hang, eventually causing an =
exception. Using the above code showed me that the response was coming =
across but that during the last readline (when null should be expected) =
is when the hang occurs. So something about getting the last bit of info =
I think.
Anyone else having this issue? Using a workaround or anything?
For further info, I am using SuSE 8.1 Pro and Mono .23. The exception i =
get is as follows:
Unhandled Exception: System.IO.IOException: Read failure ---> =
System.IO.IOException: Read failure ---> =
System.Net.Sockets.SocketException: Some sort of w32 error occurred
in (unmanaged) mono(mono_raise_exception+0x22) [0x81171f2]
in (unmanaged) =
mono(ves_icall_System_Net_Sockets_Socket_Receive_internal+0x85) =
[0x8134e85]
in <0x000f7> 00 System.Net.Sockets.Socket:Receive =
(byte[],int,int,System.Net.Sockets.SocketFlags)
in <0x00121> 00 System.Net.Sockets.Socket:Receive =
(byte[],int,int,System.Net.Sockets.SocketFlags)
in <0x00145> 00 System.Net.Sockets.NetworkStream:Read (byte[],int,int)
--- End of inner exception stack trace ---
in <0x00188> 00 System.Net.Sockets.NetworkStream:Read (byte[],int,int)
in <0x00181> 00 .HttpWebResponseStream:Read (byte[],int,int)
--- End of inner exception stack trace ---
in <0x001c4> 00 .HttpWebResponseStream:Read (byte[],int,int)
in <0x00127> 00 System.IO.StreamReader:ReadBuffer ()
in <0x00088> 00 System.IO.StreamReader:Read ()
in <0x00049> 00 System.IO.StreamReader:ReadLine ()
in <0x0018d> 00 WebPlay.Harness:Main (string[])
Appreciate anyone's musings, experience, or confirmation as a bug.
Thanks,
Sean