Пример #1
0
        async Task CloseChannelAsync(IChannel channel, CancellationToken token)
        {
            try
            {
                if (channel.State != CommunicationState.Closing && channel.State != CommunicationState.Closed)
                {
                    CloseChannelState state = new CloseChannelState(this, channel);
                    if (channel is ISessionChannel <IDuplexSession> )
                    {
                        IDuplexSession duplexSession = ((ISessionChannel <IDuplexSession>)channel).Session;
                        await duplexSession.CloseOutputSessionAsync(token);
                    }
                    else
                    {
                        await channel.CloseAsync(token);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                HandleError(e);

                if (channel is ISessionChannel <IDuplexSession> )
                {
                    channel.Abort();
                }
            }
        }
Пример #2
0
 private static void CloseChannelCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         CloseChannelState asyncState = (CloseChannelState)result.AsyncState;
         try
         {
             asyncState.Channel.EndClose(result);
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             asyncState.ListenerHandler.HandleError(exception);
         }
     }
 }
Пример #3
0
 private static void CloseOutputSessionCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         CloseChannelState asyncState = (CloseChannelState)result.AsyncState;
         try
         {
             ((ISessionChannel <IDuplexSession>)asyncState.Channel).Session.EndCloseOutputSession(result);
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             asyncState.ListenerHandler.HandleError(exception);
             asyncState.Channel.Abort();
         }
     }
 }
Пример #4
0
        private void CloseChannel(IChannel channel, TimeSpan timeout)
        {
            try
            {
                if (channel.State != CommunicationState.Closing && channel.State != CommunicationState.Closed)
                {
                    CloseChannelState state = new CloseChannelState(this, channel);
                    if (channel is ISessionChannel <IDuplexSession> )
                    {
                        IDuplexSession duplexSession = ((ISessionChannel <IDuplexSession>)channel).Session;
                        IAsyncResult   result        = duplexSession.BeginCloseOutputSession(timeout, Fx.ThunkCallback(new AsyncCallback(CloseOutputSessionCallback)), state);
                        if (result.CompletedSynchronously)
                        {
                            duplexSession.EndCloseOutputSession(result);
                        }
                    }
                    else
                    {
                        IAsyncResult result = channel.BeginClose(timeout, Fx.ThunkCallback(new AsyncCallback(CloseChannelCallback)), state);
                        if (result.CompletedSynchronously)
                        {
                            channel.EndClose(result);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                this.HandleError(e);

                if (channel is ISessionChannel <IDuplexSession> )
                {
                    channel.Abort();
                }
            }
        }
        static void CloseChannelCallback(IAsyncResult result)
        {
            if (result.CompletedSynchronously)
            {
                return;
            }

            CloseChannelState state = (CloseChannelState)result.AsyncState;

            try
            {
                state.Channel.EndClose(result);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                state.ListenerHandler.HandleError(e);
            }
        }
 private void CloseChannel(IChannel channel, TimeSpan timeout)
 {
     try
     {
         if ((channel.State != CommunicationState.Closing) && (channel.State != CommunicationState.Closed))
         {
             CloseChannelState state = new CloseChannelState(this, channel);
             if (channel is ISessionChannel<IDuplexSession>)
             {
                 IDuplexSession session = ((ISessionChannel<IDuplexSession>) channel).Session;
                 IAsyncResult result = session.BeginCloseOutputSession(timeout, Fx.ThunkCallback(new AsyncCallback(ListenerHandler.CloseOutputSessionCallback)), state);
                 if (result.CompletedSynchronously)
                 {
                     session.EndCloseOutputSession(result);
                 }
             }
             else
             {
                 IAsyncResult result2 = channel.BeginClose(timeout, Fx.ThunkCallback(new AsyncCallback(ListenerHandler.CloseChannelCallback)), state);
                 if (result2.CompletedSynchronously)
                 {
                     channel.EndClose(result2);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         this.HandleError(exception);
         if (channel is ISessionChannel<IDuplexSession>)
         {
             channel.Abort();
         }
     }
 }