public override int Read(byte [] buffer, int offset, int size)
{
if (!isRead)
{
throw new NotSupportedException("this stream does not allow reading");
}
if (totalRead >= contentLength)
{
return(0);
}
AsyncCallback cb = new AsyncCallback(ReadCallbackWrapper);
WebAsyncResult res = (WebAsyncResult)BeginRead(buffer, offset, size, cb, null);
if (!res.IsCompleted && !res.WaitUntilComplete(request.ReadWriteTimeout, false))
{
nextReadCalled = true;
cnc.Close(true);
throw new WebException("The operation has timed out.",
WebExceptionStatus.Timeout);
}
return(EndRead(res));
}