Пример #1
0
        public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            if (m_payloadHandler != null)
            {
                // attempt to gracefully close the connection, ignoring any errors (it may have been closed already by the server, etc.)
                State state;
                lock (m_lock)
                {
                    if (m_state == State.Connected || m_state == State.Failed)
                    {
                        m_state = State.Closing;
                    }
                    state = m_state;
                }

                if (state == State.Closing)
                {
                    try
                    {
                        m_payloadHandler.StartNewConversation();
                        await m_payloadHandler.WritePayloadAsync(QuitPayload.Create(), ioBehavior).ConfigureAwait(false);
                    }
                    catch (IOException)
                    {
                    }
                    catch (SocketException)
                    {
                    }
                }
            }
            ShutdownSocket();
            lock (m_lock)
                m_state = State.Closed;
        }
Пример #2
0
        public async Task DisposeAsync(CancellationToken cancellationToken)
        {
            if (m_transmitter != null)
            {
                try
                {
                    await m_transmitter.SendAsync(QuitPayload.Create(), cancellationToken).ConfigureAwait(false);

                    await m_transmitter.TryReceiveReplyAsync(cancellationToken).ConfigureAwait(false);
                }
                catch (SocketException)
                {
                    // socket may have been closed during shutdown; ignore
                }
                m_transmitter = null;
            }
            if (m_socket != null)
            {
                if (m_socket.Connected)
                {
                    m_socket.Shutdown(SocketShutdown.Both);
                }
                Utility.Dispose(ref m_socket);
            }
            m_state = State.Closed;
        }
Пример #3
0
 public void Dispose()
 {
     if (m_state == State.Connected)
     {
         try
         {
             m_transmitter.SendAsync(QuitPayload.Create(), CancellationToken.None).GetAwaiter().GetResult();
             m_transmitter.TryReceiveReplyAsync(CancellationToken.None).AsTask().GetAwaiter().GetResult();
         }
         catch (SocketException)
         {
             // socket may have been closed during shutdown; ignore
         }
     }
     m_transmitter = null;
     if (m_socket != null)
     {
         if (m_socket.Connected)
         {
             m_socket.Shutdown(SocketShutdown.Both);
         }
         Utility.Dispose(ref m_socket);
     }
     m_state = State.Closed;
 }
Пример #4
0
        public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            if (m_payloadHandler != null)
            {
                try
                {
                    m_payloadHandler.StartNewConversation();
                    await m_payloadHandler.WritePayloadAsync(QuitPayload.Create(), ioBehavior).ConfigureAwait(false);

                    await m_payloadHandler.ReadPayloadAsync(ProtocolErrorBehavior.Ignore, ioBehavior).ConfigureAwait(false);
                }
                catch (SocketException)
                {
                    // socket may have been closed during shutdown; ignore
                }
            }
            ShutdownSocket();
            m_state = State.Closed;
        }
Пример #5
0
        public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            if (m_payloadHandler != null)
            {
                // attempt to gracefully close the connection, ignoring any errors (it may have been closed already by the server, etc.)
                try
                {
                    m_payloadHandler.StartNewConversation();
                    await m_payloadHandler.WritePayloadAsync(QuitPayload.Create(), ioBehavior).ConfigureAwait(false);

                    await m_payloadHandler.ReadPayloadAsync(ProtocolErrorBehavior.Ignore, ioBehavior).ConfigureAwait(false);
                }
                catch (IOException)
                {
                }
                catch (SocketException)
                {
                }
            }
            ShutdownSocket();
            m_state = State.Closed;
        }