private LogSequence FindActiveLogSequence() { using (Stream logStream = new CircularStream(new SubStream(_fileStream, (long)_header.LogOffset, (long)_header.LogLength), Ownership.Dispose)) { LogSequence candidateActiveSequence = new LogSequence(); LogEntry logEntry = null; long oldTail; long currentTail = 0; do { oldTail = currentTail; logStream.Position = currentTail; LogSequence currentSequence = new LogSequence(); while (LogEntry.TryRead(logStream, out logEntry) && logEntry.LogGuid == _header.LogGuid && (currentSequence.Count == 0 || logEntry.SequenceNumber == currentSequence.Head.SequenceNumber + 1)) { currentSequence.Add(logEntry); logEntry = null; } if (currentSequence.Count > 0 && currentSequence.Contains(currentSequence.Head.Tail) && currentSequence.HigherSequenceThan(candidateActiveSequence)) { candidateActiveSequence = currentSequence; } if (currentSequence.Count == 0) { currentTail += LogEntry.LogSectorSize; } else { currentTail = currentSequence.Head.Position + LogEntry.LogSectorSize; } currentTail = currentTail % logStream.Length; } while (currentTail > oldTail); return candidateActiveSequence; } }
public BroadcastServer(string source) { _source = source; buffer = new CircularStream(ushort.MaxValue); }