internal void CheckStartReceive(HttpWebRequest request)
{
lock (this)
{
request.HeadersCompleted = true;
if (m_WriteList.Count == 0)
{
// aborted request, was already dispatched.
// Note it could have been aborted softly if not the first one in the pipeline
return;
}
// Note we do NOT allow receive if pipelining and the passed request is not the first one on the write queue
if (!m_ReadDone || m_WriteList[0] != (object)request)
{
// ReadStartNextRequest should take care of these cases
return;
}
// Start a receive
m_ReadDone = false;
}
if (!request.Async)
{
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CheckStartReceive() SYNC request, calling ConnectionReaderAsyncResult.InvokeCallback()");
request.ConnectionReaderAsyncResult.InvokeCallback();
}
else if (m_BytesScanned < m_BytesRead)
{
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CheckStartReceive() Calling ReadComplete, bytes unparsed = " + (m_BytesRead - m_BytesScanned));
ReadComplete(0, WebExceptionStatus.Success);
}
else if (Thread.CurrentThread.IsThreadPoolThread)
{
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CheckStartReceive() Calling PostReceive().");
PostReceive();
}
else
{
// Offload to the threadpool to protect against the case where one request's thread posts IO that another request
// depends on, but the first thread dies in the mean time.
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CheckStartReceive() ThreadPool.UnsafeQueueUserWorkItem(m_PostReceiveDelegate, this)");
ThreadPool.UnsafeQueueUserWorkItem(m_PostReceiveDelegate, this);
}
}