Commit 9bcf7165 authored by Marc Gravell's avatar Marc Gravell

better EOF handling

parent 7c42b7c8
...@@ -1027,18 +1027,22 @@ void ISocketCallback.OnHeartbeat() ...@@ -1027,18 +1027,22 @@ void ISocketCallback.OnHeartbeat()
readResult = await input.ReadAsync(); readResult = await input.ReadAsync();
} }
if (readResult.IsCompleted && readResult.Buffer.IsEmpty) var buffer = readResult.Buffer;
int handled = 0;
if(!buffer.IsEmpty)
{ {
break; // we're all done handled = ProcessBuffer(ref buffer); // updates buffer.Start
} }
var buffer = readResult.Buffer;
int handled = ProcessBuffer(ref buffer); // updates buffer.Start
allowSyncRead = handled != 0; allowSyncRead = handled != 0;
Multiplexer.Trace($"Processed {handled} messages", physicalName); Multiplexer.Trace($"Processed {handled} messages", physicalName);
input.AdvanceTo(buffer.Start, buffer.End); input.AdvanceTo(buffer.Start, buffer.End);
if (handled == 0 && readResult.IsCompleted)
{
break; // no more data, or trailing incomplete messages
}
} }
Multiplexer.Trace("EOF", physicalName); Multiplexer.Trace("EOF", physicalName);
RecordConnectionFailed(ConnectionFailureType.SocketClosed); RecordConnectionFailed(ConnectionFailureType.SocketClosed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment