Пример #1
0
        public IAsyncResult BeginSendRecord(HandshakeType handshakeType, AsyncCallback callback, object state)
        {
            HandshakeMessage message = this.GetMessage(handshakeType);

            message.Process();
            RecordProtocol.SendRecordAsyncResult sendRecordAsyncResult = new RecordProtocol.SendRecordAsyncResult(callback, state, message);
            this.BeginSendRecord(message.ContentType, message.EncodeMessage(), new AsyncCallback(this.InternalSendRecordCallback), sendRecordAsyncResult);
            return(sendRecordAsyncResult);
        }
Пример #2
0
 private void InternalSendRecordCallback(IAsyncResult ar)
 {
     RecordProtocol.SendRecordAsyncResult sendRecordAsyncResult = ar.AsyncState as RecordProtocol.SendRecordAsyncResult;
     try
     {
         this.EndSendRecord(ar);
         sendRecordAsyncResult.Message.Update();
         sendRecordAsyncResult.Message.Reset();
         sendRecordAsyncResult.SetComplete();
     }
     catch (Exception complete)
     {
         sendRecordAsyncResult.SetComplete(complete);
     }
 }
Пример #3
0
 private void InternalSendRecordCallback(IAsyncResult ar)
 {
     RecordProtocol.SendRecordAsyncResult asyncState = ar.AsyncState as RecordProtocol.SendRecordAsyncResult;
     try
     {
         this.EndSendRecord(ar);
         asyncState.Message.Update();
         asyncState.Message.Reset();
         asyncState.SetComplete();
     }
     catch (Exception ex)
     {
         asyncState.SetComplete(ex);
     }
 }
Пример #4
0
 public void EndSendRecord(IAsyncResult asyncResult)
 {
     if (asyncResult is RecordProtocol.SendRecordAsyncResult)
     {
         RecordProtocol.SendRecordAsyncResult sendRecordAsyncResult = asyncResult as RecordProtocol.SendRecordAsyncResult;
         if (!sendRecordAsyncResult.IsCompleted)
         {
             sendRecordAsyncResult.AsyncWaitHandle.WaitOne();
         }
         if (sendRecordAsyncResult.CompletedWithError)
         {
             throw sendRecordAsyncResult.AsyncException;
         }
     }
     else
     {
         this.innerStream.EndWrite(asyncResult);
     }
 }