CloseImpl() private method

private CloseImpl ( ) : void
return void
        internal void Free(HmuxConnection channel)
        {
            Success();

              lock (this) {
            _activeCount--;

            bool failing = false;

            failing = _failTime > 0 || _busyTime > 0;

            int size = (_idleHead - _idleTail + _idle.Length) % _idle.Length;

            if (!failing && size < _idleSize) {
              Trace.TraceInformation("Returning channel '{0}' to pool", channel);
              _idleHead = (_idleHead + 1) % _idle.Length;
              _idle[_idleHead] = channel;

              channel = null;
            }
              }

              long now = Utils.CurrentTimeMillis();
              long maxIdleTime = _loadBalanceIdleTime;
              HmuxConnection oldChannel = null;

              do {
            oldChannel = null;

            lock (this) {
              if (_idleHead != _idleTail) {
            int nextTail = (_idleTail + 1) % _idle.Length;

            oldChannel = _idle[nextTail];
            if (oldChannel != null
                && (oldChannel.GetIdleStartTime() + maxIdleTime) < now) {
              _idle[nextTail] = null;
              _idleTail = nextTail;
            } else {
              oldChannel = null;
            }
              }
            }

            if (oldChannel != null) {
              oldChannel.CloseImpl();
              Trace.TraceInformation("closing expired channel '{0}'", oldChannel);
            }
              } while (oldChannel != null);

              if (channel != null) {
            channel.CloseImpl();
              }
        }