protected void BackgroundThread(Object o) { LivePacketDevice dev = o as LivePacketDevice; DeviceControlBlock info = ExtraInfos[dev.Name]; while (!info.BackgroundThreadStop) { bool shouldSleep = true; lock (info.QueueLock) { if (info.PacketQueue.Count != 0) { shouldSleep = false; } } if (shouldSleep) { System.Threading.Thread.Sleep(1000); } else // should process the queue { List <Packet> ourQueue; lock (info.QueueLock) { // swap queues, giving the capture callback a new one ourQueue = info.PacketQueue; info.PacketQueue = new List <Packet>(); } StatisticsInfo ourStat = new StatisticsInfo(0, 0); double totbit = 0; DateTime earlist = DateTime.MaxValue; DateTime latest = DateTime.MinValue; foreach (var pk in ourQueue) { // Timestamp and length. if (pk.Timestamp < earlist) { earlist = pk.Timestamp; } if (pk.Timestamp > latest) { latest = pk.Timestamp; } totbit += pk.Length * 8; ourStat.CInfo += SingleAnalyzer.SortPacket(pk); } if (info.LastTimestamp != DateTime.MinValue) { double delay = (latest - info.LastTimestamp).TotalMilliseconds; ourStat.Bps = totbit * 1000 / delay; ourStat.Pps = ourQueue.Count * 1000 / delay; } else { ourStat.Bps = ourStat.Pps = 0; } info.LastTimestamp = latest; _Statistics[dev.Name] = ourStat; } } }
public MetaPacket(Packet pk) { Length = pk.Length * 8; Timestamp = pk.Timestamp; Cinfo = SingleAnalyzer.SortPacket(pk); }