diff --git a/src/main/java/com/teragrep/net_01/channel/context/Clock.java b/src/main/java/com/teragrep/net_01/channel/context/Clock.java index 48f0f8a..36f86a6 100644 --- a/src/main/java/com/teragrep/net_01/channel/context/Clock.java +++ b/src/main/java/com/teragrep/net_01/channel/context/Clock.java @@ -50,8 +50,8 @@ public interface Clock extends AutoCloseable { /** - * @param bufferLease to be consumed by the Clock. IMPORTANT: current tls implementation will not work properly if - * {@link BufferLease} is not fully consumed. + * @param bufferLease to be consumed by the Clock. Clock or it's subsequent actions must close all BufferLease's it + * receives otherwise encapsulated buffers are not reusable and memory allocator consumes time. */ void advance(BufferLease bufferLease); } diff --git a/src/main/java/com/teragrep/net_01/channel/context/IngressImpl.java b/src/main/java/com/teragrep/net_01/channel/context/IngressImpl.java index d2e67c7..534c913 100644 --- a/src/main/java/com/teragrep/net_01/channel/context/IngressImpl.java +++ b/src/main/java/com/teragrep/net_01/channel/context/IngressImpl.java @@ -108,6 +108,7 @@ public void run() { boolean continueReading = true; while (!activeBuffers.isEmpty()) { + // IMPORTANT: current tls implementation will skip bytes if BufferLeases are not fully consumed. BufferLease bufferLease = activeBuffers.removeFirst(); bufferLease.addRef(); LOGGER @@ -119,6 +120,12 @@ public void run() { if (!interestedClocks.isEmpty()) { for (Clock clock : interestedClocks) { clock.advance(bufferLease); + + if (bufferLease.buffer().hasRemaining()) { + // shared buffer between clocks, ready for another + bufferLease.addRef(); + } + } }