private void ReadLoop()
{
if (!Reading)
return;
var _buffer = new byte[1024];
var _signal = new EventSignal<CallbackDetail<int>>();
_signal.Finished += (sender, e) =>
{
if (e.Result.IsFaulted)
{
Exception exception = e.Result.Exception.GetBaseException();
if (!HttpBasedTransport.IsRequestAborted(exception))
{
if (!(exception is IOException))
m_connection.OnError(exception);
StopReading(true);
}
return;
}
int _read = e.Result.Result;
if (_read > 0)
// Put chunks in the buffer
m_buffer.Add(_buffer, _read);
if (_read == 0)
{
// Stop any reading we're doing
StopReading(true);
return;
}
// Keep reading the next set of data
ReadLoop();
if (_read <= _buffer.Length)
// If we read less than we wanted or if we filled the buffer, process it
ProcessBuffer();
};
StreamExtensions.ReadAsync(_signal, m_stream, _buffer);
}