internal bool AbortOrDisassociate(HttpWebRequest request, WebException webException)
{
GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::AbortOrDisassociate", "request#" + ValidationHelper.HashString(request));
GlobalLog.ThreadContract(ThreadKinds.Unknown, "Connection#" + ValidationHelper.HashString(this) + "::AbortOrDisassociate()");
ConnectionReturnResult result = null;
lock(this)
{
int idx = m_WriteList.IndexOf(request);
// If the request is in the submission AND this is the first request we have to abort the connection,
// Otheriwse we simply disassociate it from the current connection.
if (idx == -1)
{
idx = m_WaitList.IndexOf(request);
// If idx == -1 then the request must be already dispatched and the response stream is drained
// If so then we let request.Abort() to deal with this situation.
//
if (idx != -1)
{
m_WaitList.RemoveAt(idx);
}
GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::AbortOrDisassociate()", "Request was wisassociated");
return true;
}
else if (idx != 0)
{
// Make this connection Keep-Alive=false, remove the request and do not close the connection
// When the active request completes, the rest of the pipeline (minus aborted request) will be resubmitted.
m_WriteList.RemoveAt(idx);
m_KeepAlive = false;
GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::AbortOrDisassociate()", "Request was Disassociated from the Write List, idx = " + idx);
return true;
}
#if DEBUG
try
{
#endif
m_KeepAlive = false;
if (webException != null && m_InnerException == null)
{
m_InnerException = webException;
m_Error = webException.Status;
}
else
{
m_Error = WebExceptionStatus.RequestCanceled;
}
PrepareCloseConnectionSocket(ref result);
// Hard Close the socket.
Close(0);
#if DEBUG
}
catch (Exception exception)
{
t_LastStressException = exception;
if (!NclUtilities.IsFatal(exception)){
GlobalLog.Assert("Connection#" + ValidationHelper.HashString(this) + "::AbortOrDisassociate()", exception.Message);
}
}
#endif
}
ConnectionReturnResult.SetResponses(result);
GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::AbortOrDisassociate()", "Connection Aborted");
return false;
}