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

Fixed bug with resizing buffers #1554

Merged
Merged
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
Expand Up @@ -620,7 +620,7 @@ protected void dispatchStream(WebSocket webSocket, InputStream is) throws IOExce
while (read > -1) {
bb.position(bb.position() + read);
if (bb.remaining() == 0) {
resizeByteBuffer(webSocket);
bb = resizeByteBuffer(webSocket);
}
read = is.read(bb.array(), bb.position(), bb.remaining());
}
Expand All @@ -639,7 +639,7 @@ protected void dispatchReader(WebSocket webSocket, Reader r) throws IOException
while (read > -1) {
cb.position(cb.position() + read);
if (cb.remaining() == 0) {
resizeCharBuffer(webSocket);
cb = resizeCharBuffer(webSocket);
}
read = r.read(cb.array(), cb.position(), cb.remaining());
}
Expand All @@ -650,7 +650,7 @@ protected void dispatchReader(WebSocket webSocket, Reader r) throws IOException
}
}

private void resizeByteBuffer(WebSocket webSocket) throws IOException {
private ByteBuffer resizeByteBuffer(WebSocket webSocket) throws IOException {
int maxSize = getByteBufferMaxSize();
ByteBuffer bb = webSocket.bb;
if (bb.limit() >= maxSize) {
Expand All @@ -667,9 +667,10 @@ private void resizeByteBuffer(WebSocket webSocket) throws IOException {
bb.rewind();
newBuffer.put(bb);
webSocket.bb = newBuffer;
return newBuffer;
}

private void resizeCharBuffer(WebSocket webSocket) throws IOException {
private CharBuffer resizeCharBuffer(WebSocket webSocket) throws IOException {
int maxSize = getCharBufferMaxSize();
CharBuffer cb = webSocket.cb;
if (cb.limit() >= maxSize) {
Expand All @@ -686,6 +687,7 @@ private void resizeCharBuffer(WebSocket webSocket) throws IOException {
cb.rewind();
newBuffer.put(cb);
webSocket.cb = newBuffer;
return newBuffer;
}

/**
Expand Down