Closed
Description
ShellStream.Read returns immediately with 0 bytes read when no data is available instead of blocking the call.
Consequently the other functions implemented in the parent class Stream
that implement the asynchronous patterns based on the Read function (BeginRead/EndRead, ReadAsync) return also immediately with a 0 byte read instead of being suspended until data is available.
This prevent using correct asynchronous pattern with these functions.
The following modified function waiting on _dataReceived
when no data is available seems to work:
public override int Read(byte[] buffer, int offset, int count)
{
var i = 0;
while (true)
{
lock (_incoming)
{
for (; i < count && _incoming.Count > 0; i++)
{
buffer[offset + i] = _incoming.Dequeue();
}
}
if (i != 0)
return i;
_dataReceived.WaitOne();
}
}