Caucho.IIS.Server.OpenRecycle C# (CSharp) Method

OpenRecycle() private method

private OpenRecycle ( ) : HmuxConnection
return HmuxConnection
        private HmuxConnection OpenRecycle()
        {
            long now = Utils.CurrentTimeMillis();
              HmuxConnection channel = null;

              lock (this) {
            if (_idleHead != _idleTail) {
              channel = _idle[_idleHead];
              long freeTime = channel.GetIdleStartTime();

              _idle[_idleHead] = null;
              _idleHead = (_idleHead + _idle.Length - 1) % _idle.Length;

              if (now < freeTime + _loadBalanceIdleTime) {
            _activeCount++;

            channel.ClearIdleStartTime();
            channel.ToActive();

            Trace.TraceInformation("OpenRecycle '{0}'", channel);

            return channel;
              }
            }
              }

              if (channel != null) {
            if (_log.IsLoggable(EventLogEntryType.Information))
              _log.Info(this + " close idle " + channel
                    + " expire=" + new DateTime(channel.GetIdleStartTime() * 10 + _loadBalanceIdleTime * 10));
            Trace.TraceInformation("closing expired channel '{0}'", channel);

            channel.CloseImpl();
              }

              Trace.TraceInformation("OpenRecyle return 'null'");

              return null;
        }