protected void ReadLoop()
{
byte[] read_buffer = new byte[MTU];
BufferAllocator ba = new BufferAllocator(MTU, 1.1);
while(_running) {
int length = -1;
try {
length = _tap.Read(read_buffer);
} catch(ThreadInterruptedException x) {
if(_running && ProtocolLog.Exceptions.Enabled) {
ProtocolLog.Write(ProtocolLog.Exceptions, x.ToString());
}
} catch(Exception e) {
ProtocolLog.WriteIf(ProtocolLog.Exceptions, e.ToString());
}
if (length == 0 || length == -1) {
ProtocolLog.WriteIf(IpopLog.TapLog, "Couldn't read TAP");
continue;
}
Array.Copy(read_buffer, 0, ba.Buffer, ba.Offset, length);
MemBlock packet = MemBlock.Reference(ba.Buffer, ba.Offset, length);
ba.AdvanceBuffer(length);
Subscriber s = _sub;
if(s != null) {
try {
s.Handle(packet, this);
} catch(Exception e) {
ProtocolLog.WriteIf(ProtocolLog.Exceptions, e.ToString());
}
}
}
}