Exemplo n.º 1
0
 public void DisConnect()
 {
     lock (this)
     {
         mConnected = false;
         try
         {
             OnDisconnected();
             Token = null;
             if (mSocket != null)
             {
                 TcpClient.CloseSocket(mSocket);
                 mSocket = null;
             }
             mReceiveEventArgs.Dispose();
             mReceiveEventArgs = null;
             mSendEventArgs.Dispose();
             mSendEventArgs = null;
             mProperties.Clear();
             if (mBaseNetworkStream != null)
             {
                 mBaseNetworkStream.Dispose();
                 mBaseNetworkStream = null;
             }
             if (mSslStream != null)
             {
                 mSslStream.Dispose();
                 mSslStream = null;
             }
             object item = DequeueSendMessage();
             while (item != null)
             {
                 if (item is IBuffer)
                 {
                     Buffers.Buffer.Free(((IBuffer)item));
                 }
                 else if (item is IBuffer[])
                 {
                     foreach (IBuffer b in (IBuffer[])item)
                     {
                         Buffers.Buffer.Free(b);
                     }
                 }
                 item = DequeueSendMessage();
             }
         }
         catch
         {
         }
     }
     if (awaitPipeStream.Pending)
     {
         awaitPipeStream.Error(new SocketException((int)SocketError.ConnectionAborted));
     }
     if (mReadMessageAwait.Pending)
     {
         mReadMessageAwait.Error(new SocketException((int)SocketError.ConnectionAborted));
     }
 }
Exemplo n.º 2
0
 public void DisConnect()
 {
     lock (this)
     {
         mConnected = false;
         try
         {
             if (mSocket != null)
             {
                 TcpClient.CloseSocket(mSocket);
                 mSocket = null;
             }
             mProperties.Clear();
             if (mBaseNetworkStream != null)
             {
                 mBaseNetworkStream.Dispose();
             }
             object item = DequeueSendMessage();
             while (item != null)
             {
                 if (item is IBuffer)
                 {
                     Buffers.Buffer.Free(((IBuffer)item));
                 }
                 else if (item is IBuffer[])
                 {
                     foreach (IBuffer b in (IBuffer[])item)
                     {
                         Buffers.Buffer.Free(b);
                     }
                 }
                 item = DequeueSendMessage();
             }
         }
         catch
         {
         }
     }
 }