Created
June 4, 2013 22:24
-
-
Save bhasudha/5710154 to your computer and use it in GitHub Desktop.
Netty 3.x unbounded DynamicChannelBuffer growth. See http://stackoverflow.com/questions/12134212/trim-dynamicbuffer-to-maintain-size for more information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void ensureWritableBytes(int minWritableBytes) { | |
if (minWritableBytes <= writableBytes()) { | |
return; | |
} | |
int newCapacity; | |
if (capacity() == 0) { | |
newCapacity = 1; | |
} else { | |
newCapacity = capacity(); | |
} | |
int minNewCapacity = writerIndex() + minWritableBytes; | |
while (newCapacity < minNewCapacity) { | |
newCapacity <<= 1; | |
// Check if we exceeded the maximum size of 2gb if this is the case then | |
// newCapacity == 0 | |
// | |
// https://github.com/netty/netty/issues/258 | |
if (newCapacity == 0) { | |
throw new IllegalStateException("Maximum size of 2gb exceeded"); | |
} | |
} | |
ChannelBuffer newBuffer = factory().getBuffer(order(), newCapacity); | |
newBuffer.writeBytes(buffer, 0, writerIndex()); | |
buffer = newBuffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment