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(); } }
/** * This is a System.Threading.ThreadStart delegate * We loop waiting for edges that need to send, * or data on the socket. * * This is the only thread that can touch the socket, * therefore, we do not need to lock the socket. */ protected void MonitorLogOff() { Util.FuzzyEvent fe = _monitor_fe; _monitor_fe = null; if (fe != null) { fe.TryCancel(); } }