private void InternalWriteStartNextRequest(HttpWebRequest request, ref bool calledCloseConnection, ref TriState startRequestResult, ref HttpWebRequest nextRequest, ref ConnectionReturnResult returnResult) {
GlobalLog.ThreadContract(ThreadKinds.Unknown, "Connection#" + ValidationHelper.HashString(this) + "::InternalWriteStartNextRequest");
lock(this) {
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::WriteStartNextRequest() setting WriteDone:" + m_WriteDone.ToString() + " to true");
m_WriteDone = true;
//
// If we're not doing keep alive, and the read on this connection
// has already completed, now is the time to close the
// connection.
//
//need to wait for read to set the error
if (!m_KeepAlive || m_Error != WebExceptionStatus.Success || !CanBePooled) {
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::WriteStartNextRequest() m_WriteList.Count:" + m_WriteList.Count);
if (m_ReadDone) {
// We could be closing because of an unexpected keep-alive
// failure, ie we pipelined a few requests and in the middle
// the remote server stopped doing keep alive. In this
// case m_Error could be success, which would be misleading.
// So in that case we'll set it to connection closed.
if (m_Error == WebExceptionStatus.Success) {
// Only reason we could have gotten here is because
// we're not keeping the connection alive.
m_Error = WebExceptionStatus.KeepAliveFailure;
}
// PrepareCloseConnectionSocket is called with the critical section
// held. Note that we know since it's not a keep-alive
// connection the read half wouldn't have posted a receive
// for this connection, so it's OK to call PrepareCloseConnectionSocket now.
PrepareCloseConnectionSocket(ref returnResult);
calledCloseConnection = true;
Close();
}
else {
if (m_Error!=WebExceptionStatus.Success) {
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::WriteStartNextRequest() a Failure, m_Error = " + m_Error.ToString());
}
}
}
else {
// If we're pipelining, we get get the next request going
// as soon as the write is done. Otherwise we have to wait
// until both read and write are done.
GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::WriteStartNextRequest() Non-Error m_WriteList.Count:" + m_WriteList.Count + " m_WaitList.Count:" + m_WaitList.Count);
if (m_Pipelining || m_ReadDone)
{
nextRequest = CheckNextRequest();
}
if (nextRequest != null)
{
startRequestResult = StartRequest(nextRequest);
}
}
} // lock
}