private TriState StartRequest(HttpWebRequest request)
{
GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::StartRequest", "HttpWebRequest#" + ValidationHelper.HashString(request)+" WriteDone:"+m_WriteDone+" ReadDone: "+m_ReadDone+" WaitList:"+m_WaitList.Count+" WriteList:"+m_WriteList.Count);
GlobalLog.ThreadContract(ThreadKinds.Unknown, "Connection#" + ValidationHelper.HashString(this) + "::StartRequest");
if (m_WriteList.Count == 0 && ServicePoint.MaxIdleTime != -1 && m_IdleSinceUtc != DateTime.MinValue && m_IdleSinceUtc + TimeSpan.FromMilliseconds(ServicePoint.MaxIdleTime) < DateTime.UtcNow)
{
// This actually means that this connection was done with reading last response more than MaxIdle milliseconds ago.
// We want to renew this connection in fear that the server has sent as a TCP FIN by closing an idle connection.
GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::StartRequest() Expired connection was idle for (sec) " + (int)((DateTime.UtcNow - m_IdleSinceUtc).TotalSeconds) + ", request will be retried: #"+ValidationHelper.HashString(request));
return TriState.Unspecified; // The caller has close this one and find another Connection
}
TriState needReConnect = TriState.False;
// Starting a request means the connection is not idle anymore
m_IdleSinceUtc = DateTime.MinValue;
// Initialze state, and add the request to the write queue.
//
// Note that m_Pipelining shold be only set here but the sanity check is made by the caller
// means if the caller has found that it is safe to pipeline the below result must be true as well
//
if (!m_IsPipelinePaused)
m_IsPipelinePaused = m_WriteList.Count >= s_MaxPipelinedCount;
m_Pipelining = m_CanPipeline && request.Pipelined && (!request.RequireBody);
m_KeepAlive &= (request.KeepAlive || request.NtlmKeepAlive);
// start of write process, disable done-ness flag
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::StartRequest() setting WriteDone:" + m_WriteDone.ToString() + " to false");
m_WriteDone = false;
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::StartRequest() m_WriteList adding HttpWebRequest#" + ValidationHelper.HashString(request));
m_WriteList.Add(request);
GlobalLog.Print(m_WriteList.Count+" requests queued");
CheckNonIdle();
// with no network stream around, we will have to create one, therefore, we can't have
// the possiblity to even have a DoneReading().
if (IsInitalizing)
needReConnect = TriState.True;
GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::StartRequest", needReConnect.ToString());
return needReConnect;
}