protected override void OnSend(Message message, TimeSpan timeout)
            {
                TimeoutHelper         timeoutHelper        = new TimeoutHelper(timeout);
                ChannelPoolKey        key                  = null;
                bool                  isConnectionFromPool = true;
                IDuplexSessionChannel channel              = this.GetChannelFromPool(ref timeoutHelper, out key, out isConnectionFromPool);
                bool                  flag2                = false;

                try
                {
                    if (!isConnectionFromPool)
                    {
                        this.StampInitialMessage(message);
                        channel.Open(timeoutHelper.RemainingTime());
                        this.StartBackgroundReceive(channel);
                    }
                    channel.Send(message, timeoutHelper.RemainingTime());
                    flag2 = true;
                }
                finally
                {
                    if (!flag2)
                    {
                        this.CleanupChannel(channel, false, key, isConnectionFromPool, ref timeoutHelper);
                    }
                }
                this.CleanupChannel(channel, true, key, isConnectionFromPool, ref timeoutHelper);
            }
Exemple #2
0
            protected override void OnSend(Message message, TimeSpan timeout)
            {
                TimeoutHelper         timeoutHelper        = new TimeoutHelper(timeout);
                ChannelPoolKey        key                  = null;
                bool                  isConnectionFromPool = true;
                IDuplexSessionChannel innerChannel         =
                    GetChannelFromPool(ref timeoutHelper, out key, out isConnectionFromPool);

                bool success = false;

                try
                {
                    if (!isConnectionFromPool)
                    {
                        StampInitialMessage(message);
                        innerChannel.Open(timeoutHelper.RemainingTime());
                        StartBackgroundReceive(innerChannel);
                    }

                    innerChannel.Send(message, timeoutHelper.RemainingTime());
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        CleanupChannel(innerChannel, false, key, isConnectionFromPool, ref timeoutHelper);
                    }
                }

                CleanupChannel(innerChannel, true, key, isConnectionFromPool, ref timeoutHelper);
            }
 private void CleanupChannel(IDuplexSessionChannel channel, bool connectionStillGood, ChannelPoolKey key, bool isConnectionFromPool, ref TimeoutHelper timeoutHelper)
 {
     if (isConnectionFromPool)
     {
         this.channelPool.ReturnConnection(key, channel, connectionStillGood, timeoutHelper.RemainingTime());
     }
     else if (connectionStillGood)
     {
         this.channelPool.AddConnection(key, channel, timeoutHelper.RemainingTime());
     }
     else
     {
         channel.Abort();
     }
 }
 private IDuplexSessionChannel GetChannelFromPool(ref TimeoutHelper timeoutHelper, out ChannelPoolKey key, out bool isConnectionFromPool)
 {
     isConnectionFromPool = true;
     while (true)
     {
         IDuplexSessionChannel connection = this.channelPool.TakeConnection(this.RemoteAddress, this.Via, timeoutHelper.RemainingTime(), out key);
         if (connection == null)
         {
             isConnectionFromPool = false;
             return(this.innerFactory.CreateChannel(this.RemoteAddress, this.Via));
         }
         if (connection.State == CommunicationState.Opened)
         {
             return(connection);
         }
         this.channelPool.ReturnConnection(key, connection, false, timeoutHelper.RemainingTime());
     }
 }
Exemple #5
0
            IDuplexSessionChannel GetChannelFromPool(ref TimeoutHelper timeoutHelper, out ChannelPoolKey key,
                                                     out bool isConnectionFromPool)
            {
                isConnectionFromPool = true;
                while (true)
                {
                    IDuplexSessionChannel pooledChannel
                        = this.channelPool.TakeConnection(this.RemoteAddress, this.Via, timeoutHelper.RemainingTime(), out key);

                    if (pooledChannel == null)
                    {
                        isConnectionFromPool = false;
                        return(this.innerFactory.CreateChannel(RemoteAddress, Via));
                    }

                    // only return good connections
                    if (pooledChannel.State == CommunicationState.Opened)
                    {
                        return(pooledChannel);
                    }

                    // Abort stale connections from the pool
                    this.channelPool.ReturnConnection(key, pooledChannel, false, timeoutHelper.RemainingTime());
                }
            }