Added networking optimization, to avoid wasted processing on every read.

Thanks to @catbref for finding this.
This commit is contained in:
CalDescent 2022-01-22 18:43:32 +00:00
parent b30445c5f8
commit 25efee55b8

View File

@ -473,6 +473,7 @@ public class Peer {
return;
}
if (LOGGER.isTraceEnabled()) {
if (bytesRead > 0) {
byte[] leadingBytes = new byte[Math.min(bytesRead, 8)];
this.byteBuffer.asReadOnlyBuffer().position(priorPosition).get(leadingBytes);
@ -484,6 +485,7 @@ public class Peer {
LOGGER.trace("[{}] Received {} bytes into byteBuffer[{}] from peer {}", this.peerConnectionId,
bytesRead, priorPosition, this);
}
}
final boolean wasByteBufferFull = !this.byteBuffer.hasRemaining();
while (true) {