Groups | Blog | Home
all groups > dotnet sdk > may 2007 >

dotnet sdk : NetworkStream.Read return 0 bytes when timeout is INFINITE



Jeevaka
5/15/2007 11:58:03 AM
I have code similar to below:

myTcpClient.GetStream().ReadTimeout = Timeout.Infinite;
int readLength = myTcpClient.GetStream().Read(buffer, 0, expectedLength);

where myTcpClient is a TcpClient instance that is connected to a server. I
expect this to either return a number > 0 or throw an exception and it works
like that for months. But once in a while, when the system is busy, this
returns 0. (I.e. return without reading anything.) Could this be a bug in the
..NET socket API?
Rick Strahl [MVP]
5/17/2007 12:44:11 AM
If the stream is at the end you might see this. You could have a situation
where the stream contains no data...

+++Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com/weblog


[quoted text, click to view]
Jeevaka
5/17/2007 6:35:00 AM
Hi Rick,

By 'stream is at the end' do you mean there is no data in the stream or that
the other end is closed? If you mean 'no data' shouldn't it block till there
is data rather than timeout? Extract from documentation for 'ReadTimeout':
"The default value, Infinite, specifies that the read operation does not time
out.". In this case the other end is not closed.

I reported this as a bug to MS and they got back telling it is not
reproduceable. Of course it happens only rarely. It seems at least they agree
that the behaviour is not expected.

Thanks
AddThis Social Bookmark Button