Brunet.Transport.UdpEdgeListener.MonitorLogSwitch C# (CSharp) Method

MonitorLogSwitch() protected method

protected MonitorLogSwitch ( ) : void
return void
    protected void MonitorLogSwitch()
    {
      if(_running == 0) {
        MonitorLogOff();
        return;
      }

      if(ProtocolLog.Monitor.Enabled) {
        EndPoint ep = new IPEndPoint(IPAddress.Loopback, _port);
        Action<DateTime> log_todo = delegate(DateTime dt) {
          SendControlPacket(ep, 0, 0, ControlCode.Log, null);
        };
        int millisec_timeout = 5000; //log every 5 seconds.
        Util.FuzzyEvent fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(log_todo,
            millisec_timeout, millisec_timeout/2);
        if(Interlocked.CompareExchange(ref _monitor_fe, fe, null) != null) {
          fe.TryCancel();
        }
      }

      if(_running == 0 || !ProtocolLog.Monitor.Enabled) {
        MonitorLogOff();
      }
    }