Inheritance: LazyAsyncResult
コード例 #1
0
        //
        // Resumes async Read or Write after the handshake is done
        //
        private void ResumeIO(BufferAsyncResult bufferResult)
        {
            IAsyncResult result;

            if (bufferResult.IsWrite)
            {
                if (bufferResult.Buffers != null)
                {
                    result = m_Worker.SecureStream.BeginWrite(bufferResult.Buffers, _CompleteIOCallback, bufferResult);
                }
                else
                {
                    result = m_Worker.SecureStream.BeginWrite(bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, _CompleteIOCallback, bufferResult);
                }
            }
            else
            {
                result = m_Worker.SecureStream.BeginRead(bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, _CompleteIOCallback, bufferResult);
            }

            if (result.CompletedSynchronously)
            {
                CompleteIO(result);
            }
        }
コード例 #2
0
 internal override IAsyncResult BeginMultipleWrite(BufferOffsetSize[] buffers, AsyncCallback callback, object state)
 {
     IAsyncResult result2;
     if (!this.m_Worker.IsAuthenticated)
     {
         BufferAsyncResult result = new BufferAsyncResult(this, buffers, state, callback);
         if (this.ProcessAuthentication(result))
         {
             return result;
         }
     }
     try
     {
         result2 = this.m_Worker.SecureStream.BeginWrite(buffers, callback, state);
     }
     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.SendFailure;
         }
         throw;
     }
     return result2;
 }
コード例 #3
0
        internal override IAsyncResult BeginMultipleWrite(BufferOffsetSize[] buffers, AsyncCallback callback, object state)
        {
            GlobalLog.Print("TlsStream#" + ValidationHelper.HashString(this) + "::BeginMultipleWrite() SecureWorker#" + ValidationHelper.HashString(m_Worker) + " buffers.Length:" + buffers.Length.ToString());
            if (!m_Worker.IsAuthenticated)
            {
                BufferAsyncResult result = new BufferAsyncResult(this, buffers, state, callback);
                if (ProcessAuthentication(result))
                {
                    return(result);
                }
            }

            try {
                return(m_Worker.SecureStream.BeginWrite(buffers, callback, state));
            }
            catch {
                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;
            }
        }
コード例 #4
0
        //
        // BeginWrite -
        //
        // Write the bytes to the write - while encrypting
        //
        // copy plain text data to a temporary buffer
        // encrypt the data
        // once the data is encrypted clear the plain text for security
        //
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback asyncCallback, object asyncState)
        {
            GlobalLog.Print("TlsStream#" + ValidationHelper.HashString(this) + "::BeginWrite() SecureWorker#" + ValidationHelper.HashString(m_Worker) + " offset:" + offset.ToString() + " size:" + size.ToString());
            if (!m_Worker.IsAuthenticated)
            {
                BufferAsyncResult result = new BufferAsyncResult(this, buffer, offset, size, true, asyncState, asyncCallback);
                if (ProcessAuthentication(result))
                {
                    return(result);
                }
            }

            try {
                return(m_Worker.SecureStream.BeginWrite(buffer, offset, size, asyncCallback, asyncState));
            }
            catch {
                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;
            }
        }
コード例 #5
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback asyncCallback, object asyncState)
        {
            IAsyncResult result2;

            if (!this.m_Worker.IsAuthenticated)
            {
                BufferAsyncResult result = new BufferAsyncResult(this, buffer, offset, size, false, asyncState, asyncCallback);
                if (this.ProcessAuthentication(result))
                {
                    return(result);
                }
            }
            try
            {
                result2 = this.m_Worker.SecureStream.BeginRead(buffer, offset, size, asyncCallback, asyncState);
            }
            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(result2);
        }
コード例 #6
0
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback asyncCallback, object asyncState)
 {
     IAsyncResult result2;
     if (!this.m_Worker.IsAuthenticated)
     {
         BufferAsyncResult result = new BufferAsyncResult(this, buffer, offset, size, false, asyncState, asyncCallback);
         if (this.ProcessAuthentication(result))
         {
             return result;
         }
     }
     try
     {
         result2 = this.m_Worker.SecureStream.BeginRead(buffer, offset, size, asyncCallback, asyncState);
     }
     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 result2;
 }
コード例 #7
0
 internal IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
 {
     BufferAsyncResult userAsyncResult = new BufferAsyncResult(this, buffer, offset, count, asyncState, asyncCallback);
     AsyncProtocolRequest asyncRequest = new AsyncProtocolRequest(userAsyncResult);
     this.ProcessRead(buffer, offset, count, asyncRequest);
     return userAsyncResult;
 }
コード例 #8
0
        internal override IAsyncResult BeginMultipleWrite(BufferOffsetSize[] buffers, AsyncCallback callback, object state)
        {
            IAsyncResult result2;

            if (!this.m_Worker.IsAuthenticated)
            {
                BufferAsyncResult result = new BufferAsyncResult(this, buffers, state, callback);
                if (this.ProcessAuthentication(result))
                {
                    return(result);
                }
            }
            try
            {
                result2 = this.m_Worker.SecureStream.BeginWrite(buffers, callback, state);
            }
            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.SendFailure;
                }
                throw;
            }
            return(result2);
        }
コード例 #9
0
        private static void CompleteIO(IAsyncResult result)
        {
            BufferAsyncResult asyncState = (BufferAsyncResult)result.AsyncState;
            object            obj2       = null;

            if (asyncState.IsWrite)
            {
                ((TlsStream)asyncState.AsyncObject).m_Worker.SecureStream.EndWrite(result);
            }
            else
            {
                obj2 = ((TlsStream)asyncState.AsyncObject).m_Worker.SecureStream.EndRead(result);
            }
            asyncState.InvokeCallback(obj2);
        }
コード例 #10
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;
            }
        }
コード例 #11
0
        private static void CompleteIO(IAsyncResult result)
        {
            BufferAsyncResult bufferResult = (BufferAsyncResult)result.AsyncState;

            object readBytes = null;

            if (bufferResult.IsWrite)
            {
                ((TlsStream)bufferResult.AsyncObject).m_Worker.SecureStream.EndWrite(result);
            }
            else
            {
                readBytes = ((TlsStream)bufferResult.AsyncObject).m_Worker.SecureStream.EndRead(result);
            }

            bufferResult.InvokeCallback(readBytes);
        }
コード例 #12
0
 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;
     }
 }
コード例 #13
0
        private void ResumeIOWorker(object result)
        {
            BufferAsyncResult bufferResult = (BufferAsyncResult)result;

            try
            {
                ResumeIO(bufferResult);
            }
            catch (Exception exception)
            {
                if (exception is OutOfMemoryException || exception is StackOverflowException || exception is ThreadAbortException)
                {
                    throw;
                }
                if (bufferResult.InternalPeekCompleted)
                {
                    throw;
                }
                bufferResult.InvokeCallback(exception);
            }
        }
コード例 #14
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;
            }
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: _TLSstream.cs プロジェクト: REALTOBIZ/mono
        //
        // BeginWrite -
        //
        // Write the bytes to the write - while encrypting
        //
        // copy plain text data to a temporary buffer
        // encrypt the data
        // once the data is encrypted clear the plain text for security
        //
        public override IAsyncResult BeginWrite( byte[] buffer, int offset, int size, AsyncCallback asyncCallback, object asyncState) {
            GlobalLog.Print("TlsStream#" + ValidationHelper.HashString(this) + "::BeginWrite() SecureWorker#" + ValidationHelper.HashString(m_Worker) + " offset:" + offset.ToString() + " size:" + size.ToString());
            if (!m_Worker.IsAuthenticated)
            {
                BufferAsyncResult result = new BufferAsyncResult(this, buffer, offset, size, true, asyncState, asyncCallback);
                if (ProcessAuthentication(result))
                    return result;
            }

            try {
                return m_Worker.SecureStream.BeginWrite(buffer, offset, size, asyncCallback, asyncState);
            }
            catch {
                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;
            }
        }
コード例 #17
0
ファイル: _TLSstream.cs プロジェクト: REALTOBIZ/mono
        //
        // Resumes async Read or Write after the handshake is done
        //
        private void ResumeIO(BufferAsyncResult bufferResult)
        {
            IAsyncResult result;
            if (bufferResult.IsWrite)
            {
                if (bufferResult.Buffers != null)
                    result = m_Worker.SecureStream.BeginWrite(bufferResult.Buffers, _CompleteIOCallback, bufferResult);
                else
                    result = m_Worker.SecureStream.BeginWrite(bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, _CompleteIOCallback, bufferResult);
            }
            else
            {
                result = m_Worker.SecureStream.BeginRead(bufferResult.Buffer, bufferResult.Offset, bufferResult.Count, _CompleteIOCallback, bufferResult);
            }

            if (result.CompletedSynchronously)
            {
                CompleteIO(result);
            }
        }
コード例 #18
0
ファイル: Connection.cs プロジェクト: remobjects/internetpack
		public override IAsyncResult BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
		{
			if (!this.BufferedAsync)
				return IntBeginRead(buffer, offset, count, callback, state);

			AsyncRequest lRequest = new AsyncRequest();
			lRequest.AsyncBuffer = buffer;
			lRequest.AsyncOffset = offset;
			lRequest.AsyncCount = count;
			lRequest.AsyncRest = count;
			lRequest.AsyncCallback = callback;
			lRequest.AsyncState = state;

			try
			{
				if (fBuffer != null && fBufferEnd - fBufferStart > 0)
				{
					IAsyncResult lAr = new BufferAsyncResult(buffer, offset, count, lRequest);
					IntReadCallback(lAr);

					return lAr;
				}

				IntBeginRead(buffer, offset, count, IntReadCallback, lRequest);
			}
			catch (ObjectDisposedException) // disconnect from this side
			{
				TriggerAsyncDisconnect();
				throw;
			}
			catch (SocketException) // disconnect
			{
				TriggerAsyncDisconnect();
				throw;
			}

			return lRequest;
		}
コード例 #19
0
ファイル: Connection.cs プロジェクト: nolith/internetpack
        protected virtual IAsyncResult IntBeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
        {
            if (fBuffer != null && fBufferEnd - fBufferStart > 0)
            {
                IAsyncResult lAr = new BufferAsyncResult(buffer, offset, count, state);
                callback(lAr);

                return lAr;
            }

            return fDataSocket.BeginReceive(buffer, offset, count, SocketFlags.None, callback, state);
        }
コード例 #20
0
ファイル: _TLSstream.cs プロジェクト: REALTOBIZ/mono
        internal override IAsyncResult BeginMultipleWrite(BufferOffsetSize[] buffers, AsyncCallback callback, object state) {
            GlobalLog.Print("TlsStream#" + ValidationHelper.HashString(this) + "::BeginMultipleWrite() SecureWorker#" + ValidationHelper.HashString(m_Worker) + " buffers.Length:" + buffers.Length.ToString());
            if (!m_Worker.IsAuthenticated)
            {
                BufferAsyncResult result = new BufferAsyncResult(this, buffers, state, callback);
                if (ProcessAuthentication(result))
                    return result;
            }

            try {
                return m_Worker.SecureStream.BeginWrite(buffers, callback, state);
            }
            catch {
                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;
            }
        }