示例#1
0
        public override void EndWrite(IAsyncResult asyncResult)
        {
            GlobalLog.Print("TlsStream#" + ValidationHelper.HashString(this) + "::EndWrite() IAsyncResult#" + ValidationHelper.HashString(asyncResult));

            try {
                BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult;

                if (bufferResult == null || (object)bufferResult.AsyncObject != this)
                {
                    m_Worker.SecureStream.EndWrite(asyncResult);
                }
                else
                {
                    // we have wrapped user IO in case when handshake was not done as the Begin call
                    bufferResult.InternalWaitForCompletion();
                    Exception e = bufferResult.Result as Exception;
                    if (e != null)
                    {
                        throw e;
                    }
                }
            }
            catch {
                //HttpWebRequest depends on the stream to be dropped on a write error.
                Socket chkSocket = this.Socket;
                if (chkSocket != null)
                {
                    chkSocket.InternalShutdown(SocketShutdown.Both);
                }
                // We also preserve the original status of a failure because the read
                // side will now fail with object dispose error.
                if (m_Worker.IsCertValidationFailed)
                {
                    m_ExceptionStatus = WebExceptionStatus.TrustFailure;
                }
                else if (m_Worker.LastSecurityStatus != SecurityStatus.OK)
                {
                    m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
                }
                else
                {
                    m_ExceptionStatus = WebExceptionStatus.SendFailure;
                }
                throw;
            }
        }
 public override void EndWrite(IAsyncResult asyncResult)
 {
     try
     {
         BufferAsyncResult result = asyncResult as BufferAsyncResult;
         if ((result == null) || (result.AsyncObject != this))
         {
             this.m_Worker.SecureStream.EndWrite(asyncResult);
         }
         else
         {
             result.InternalWaitForCompletion();
             Exception exception = result.Result as Exception;
             if (exception != null)
             {
                 throw exception;
             }
         }
     }
     catch
     {
         Socket socket = base.Socket;
         if (socket != null)
         {
             socket.InternalShutdown(SocketShutdown.Both);
         }
         if (this.m_Worker.IsCertValidationFailed)
         {
             this.m_ExceptionStatus = WebExceptionStatus.TrustFailure;
         }
         else if (this.m_Worker.LastSecurityStatus != SecurityStatus.OK)
         {
             this.m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
         }
         else
         {
             this.m_ExceptionStatus = WebExceptionStatus.SendFailure;
         }
         throw;
     }
 }
示例#3
0
        //
        public override int EndRead(IAsyncResult asyncResult)
        {
            GlobalLog.Print("TlsStream#" + ValidationHelper.HashString(this) + "::EndRead() IAsyncResult#" + ValidationHelper.HashString(asyncResult));
            try {
                BufferAsyncResult bufferResult = asyncResult as BufferAsyncResult;

                if (bufferResult == null || (object)bufferResult.AsyncObject != this)
                {
                    return(m_Worker.SecureStream.EndRead(asyncResult));
                }

                // we have wrapped user IO in case when handshake was not done as the Begin call
                bufferResult.InternalWaitForCompletion();
                Exception e = bufferResult.Result as Exception;
                if (e != null)
                {
                    throw e;
                }

                return((int)bufferResult.Result);
            }
            catch {
                if (m_Worker.IsCertValidationFailed)
                {
                    m_ExceptionStatus = WebExceptionStatus.TrustFailure;
                }
                else if (m_Worker.LastSecurityStatus != SecurityStatus.OK)
                {
                    m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
                }
                else
                {
                    m_ExceptionStatus = WebExceptionStatus.ReceiveFailure;
                }
                throw;
            }
        }
        public override int EndRead(IAsyncResult asyncResult)
        {
            int num;

            try
            {
                BufferAsyncResult result = asyncResult as BufferAsyncResult;
                if ((result == null) || (result.AsyncObject != this))
                {
                    return(this.m_Worker.SecureStream.EndRead(asyncResult));
                }
                result.InternalWaitForCompletion();
                Exception exception = result.Result as Exception;
                if (exception != null)
                {
                    throw exception;
                }
                num = (int)result.Result;
            }
            catch
            {
                if (this.m_Worker.IsCertValidationFailed)
                {
                    this.m_ExceptionStatus = WebExceptionStatus.TrustFailure;
                }
                else if (this.m_Worker.LastSecurityStatus != SecurityStatus.OK)
                {
                    this.m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
                }
                else
                {
                    this.m_ExceptionStatus = WebExceptionStatus.ReceiveFailure;
                }
                throw;
            }
            return(num);
        }