コード例 #1
0
        private void CompleteStartRequest(bool onSubmitThread, HttpWebRequest request, TriState needReConnect) {
            GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest", ValidationHelper.HashString(request));
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest");

            if (needReConnect == TriState.True) {
                // Socket is not alive.

                GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest() Queue StartConnection Delegate ");
                try {
                    if (request.Async) {
                        CompleteStartConnection(true, request);
                    }
                    else if (onSubmitThread) {
                        CompleteStartConnection(false, request);
                    }
                    // else - fall through and wake up other thread
                }
                catch (Exception exception) {
                    GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest(): exception: " + exception.ToString());
                    if (NclUtilities.IsFatal(exception)) throw;
                    //
                    // Should not be here because CompleteStartConnection and below tries to catch everything
                    //
                    GlobalLog.Assert(exception.ToString());
                }

                // If neeeded wake up other thread where SubmitRequest was called
                if (!request.Async) {
                    GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest() Invoking Async Result");
                    request.ConnectionAsyncResult.InvokeCallback(new AsyncTriState(needReConnect));
                }


                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest", "needReConnect");
                return;
            }


            //
            // From now on the request.SetRequestSubmitDone must be called or it may hang
            // For a [....] request the write side reponse windowwas opened in HttpWebRequest.SubmitRequest
            if (request.Async)
                request.OpenWriteSideResponseWindow();


            ConnectStream writeStream = new ConnectStream(this, request);

            // Call the request to let them know that we have a write-stream, this might invoke Send() call
            if (request.Async || onSubmitThread) {
                request.SetRequestSubmitDone(writeStream);
            }
            else {
                GlobalLog.Print("Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest() Invoking Async Result");
                request.ConnectionAsyncResult.InvokeCallback(writeStream);
            }
            GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteStartRequest");
        }
コード例 #2
0
        private void CompleteConnection(bool async, HttpWebRequest request)
        {
            GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection", "async:" + async.ToString() + " request:" + ValidationHelper.HashString(request));
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection");

            WebExceptionStatus ws = WebExceptionStatus.ConnectFailure;
            //
            // From now on the request.SetRequestSubmitDone must be called or it may hang
            // For a [....] request the write side reponse windowwas opened in HttpWebRequest.SubmitRequest
            if (request.Async)
                request.OpenWriteSideResponseWindow();

            try
            {
                try {
#if !FEATURE_PAL
                    if (request.Address.Scheme == Uri.UriSchemeHttps) {
                        TlsStream tlsStream = new TlsStream(request.GetRemoteResourceUri().IdnHost,
                            NetworkStream, request.ClientCertificates, ServicePoint, request,
                            request.Async ? request.GetConnectingContext().ContextCopy : null);
                        NetworkStream = tlsStream;
                    }
#endif
                    ws = WebExceptionStatus.Success;
                }
                catch {
                    // The TLS stream could not be created.  Close the current non-TLS stream immediately
                    // to prevent any future use of it.  Due to race conditions, the error handling will sometimes
                    // try to write (flush) out some of the HTTP headers to the stream as it is closing down the failed 
                    // HttpWebRequest. This would cause plain text to go on the wire even though the stream should
                    // have been TLS encrypted.
                    NetworkStream.Close();
                    throw;
                }
                finally {
                    //
                    // There is a ---- with Abort so TlsStream ctor may throw.
                    // SetRequestSubmitDone will deal with this kind of errors.
                    // 

                    m_ReadState = ReadState.Start;
                    ClearReaderState();

                    request.SetRequestSubmitDone(new ConnectStream(this, request));
                }
            }
            catch (Exception exception)
            {
                if (m_InnerException == null)
                    m_InnerException = exception;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    ws = webException.Status;
                }
            }

            if (ws != WebExceptionStatus.Success)
            {
                ConnectionReturnResult returnResult = null;
                HandleError(false, false, ws, ref returnResult);
                ConnectionReturnResult.SetResponses(returnResult);

                if (Logging.On) Logging.PrintError(Logging.Web, this, "CompleteConnection", "on error");
                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection", "on error");
            }
            else
            {
                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection");
            }
        }
コード例 #3
0
 private void CompleteStartRequest(bool onSubmitThread, HttpWebRequest request, TriState needReConnect)
 {
     if (needReConnect == TriState.True)
     {
         try
         {
             if (request.Async)
             {
                 this.CompleteStartConnection(true, request);
             }
             else if (onSubmitThread)
             {
                 this.CompleteStartConnection(false, request);
             }
         }
         catch (Exception exception)
         {
             if (NclUtilities.IsFatal(exception))
             {
                 throw;
             }
         }
         if (!request.Async)
         {
             request.ConnectionAsyncResult.InvokeCallback(new AsyncTriState(needReConnect));
         }
     }
     else
     {
         if (request.Async)
         {
             request.OpenWriteSideResponseWindow();
         }
         ConnectStream submitStream = new ConnectStream(this, request);
         if (request.Async || onSubmitThread)
         {
             request.SetRequestSubmitDone(submitStream);
         }
         else
         {
             request.ConnectionAsyncResult.InvokeCallback(submitStream);
         }
     }
 }
コード例 #4
0
ファイル: connection.cs プロジェクト: svermeulen/iris
        private void CompleteConnection(bool async, HttpWebRequest request)
        {
            GlobalLog.Enter("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection", "async:" + async.ToString() + " request:" + ValidationHelper.HashString(request));
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection");

            WebExceptionStatus ws = WebExceptionStatus.ConnectFailure;
            //
            // From now on the request.SetRequestSubmitDone must be called or it may hang
            // For a sync request the write side reponse windowwas opened in HttpWebRequest.SubmitRequest
            if (request.Async)
                request.OpenWriteSideResponseWindow();

            try
            {
                try {
                }
                finally {
                    m_ReadState = ReadState.Start;
                    ClearReaderState();

                    request.SetRequestSubmitDone(new ConnectStream(this, request));
                    ws = WebExceptionStatus.Success;
                }

            }
            catch (Exception exception)
            {
                if (m_InnerException == null)
                    m_InnerException = exception;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    ws = webException.Status;
                }
            }

            if (ws != WebExceptionStatus.Success)
            {
                ConnectionReturnResult returnResult = null;
                HandleError(false, false, ws, ref returnResult);
                ConnectionReturnResult.SetResponses(returnResult);

                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection", "on error");
            }
            else
            {
                GlobalLog.Leave("Connection#" + ValidationHelper.HashString(this) + "::CompleteConnection");
            }
        }
コード例 #5
0
 private void CompleteConnection(bool async, HttpWebRequest request)
 {
     WebExceptionStatus connectFailure = WebExceptionStatus.ConnectFailure;
     if (request.Async)
     {
         request.OpenWriteSideResponseWindow();
     }
     try
     {
         try
         {
             if (request.Address.Scheme == Uri.UriSchemeHttps)
             {
                 TlsStream stream = new TlsStream(request.GetRemoteResourceUri().Host, base.NetworkStream, request.ClientCertificates, this.ServicePoint, request, request.Async ? request.GetConnectingContext().ContextCopy : null);
                 base.NetworkStream = stream;
             }
         }
         finally
         {
             this.m_ReadState = ReadState.Start;
             this.ClearReaderState();
             request.SetRequestSubmitDone(new ConnectStream(this, request));
             connectFailure = WebExceptionStatus.Success;
         }
     }
     catch (Exception exception)
     {
         if (this.m_InnerException == null)
         {
             this.m_InnerException = exception;
         }
         WebException exception2 = exception as WebException;
         if (exception2 != null)
         {
             connectFailure = exception2.Status;
         }
     }
     if (connectFailure != WebExceptionStatus.Success)
     {
         ConnectionReturnResult returnResult = null;
         this.HandleError(false, false, connectFailure, ref returnResult);
         ConnectionReturnResult.SetResponses(returnResult);
     }
 }