Skip to content

Commit

Permalink
Merge pull request #1554 from claymore-minds/atmosphere-2.1.x
Browse files Browse the repository at this point in the history
Fixed bug with resizing buffers
  • Loading branch information
jfarcand committed Apr 10, 2014
2 parents 00a4360 + a86c977 commit b5779e3
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit b5779e3

Please sign in to comment.