Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #6470 - remove ByteBufferPool usage from MessageInputStream #6485

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -25,14 +25,11 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.NullByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.SuspendToken;
import org.eclipse.jetty.websocket.common.WebSocketSession;

/**
* Support class for reading a (single) WebSocket BINARY message via a InputStream.
@@ -45,7 +42,6 @@ public class MessageInputStream extends InputStream implements MessageAppender
private static final ByteBuffer EOF = ByteBuffer.allocate(0).asReadOnlyBuffer();

private final Session session;
private final ByteBufferPool bufferPool;
private final BlockingDeque<ByteBuffer> buffers = new LinkedBlockingDeque<>();
private final long timeoutMs;
private ByteBuffer activeBuffer = null;
@@ -84,7 +80,6 @@ public MessageInputStream(Session session, int timeoutMs)
{
this.timeoutMs = timeoutMs;
this.session = session;
this.bufferPool = (session instanceof WebSocketSession) ? ((WebSocketSession)session).getBufferPool() : new NullByteBufferPool();
}

@Override
@@ -156,16 +151,6 @@ public void close()
if (remainingContent)
LOG.warn("MessageInputStream closed without fully consuming content {}", session);


// Release any buffers taken from the pool.
if (activeBuffer != null && activeBuffer != EOF)
bufferPool.release(activeBuffer);

for (ByteBuffer buffer : buffers)
{
bufferPool.release(buffer);
}

activeBuffer = null;
buffers.clear();
state = State.CLOSED;
@@ -258,8 +243,6 @@ public int read(byte[] b, int off, int len) throws IOException
SuspendToken resume = null;
synchronized (this)
{
// Release buffer back to pool.
bufferPool.release(activeBuffer);
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved
activeBuffer = null;

switch (state)
@@ -325,6 +308,9 @@ public boolean markSupported()

private ByteBuffer acquire(int capacity, boolean direct)
{
return bufferPool.acquire(capacity, direct);
if (direct)
return BufferUtil.allocateDirect(capacity);
else
return BufferUtil.allocate(capacity);
}
}