|
@@ -294,9 +294,14 @@ public abstract class SocketChannelContext extends ChannelContext<SocketChannel>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Currently we limit to 64KB. This is a trade-off which means more syscalls, in exchange for less
|
|
|
+ // copying.
|
|
|
+ private final int WRITE_LIMIT = 1 << 16;
|
|
|
+
|
|
|
protected int flushToChannel(ByteBuffer buffer) throws IOException {
|
|
|
int initialPosition = buffer.position();
|
|
|
ByteBuffer ioBuffer = getSelector().getIoBuffer();
|
|
|
+ ioBuffer.limit(Math.min(WRITE_LIMIT, ioBuffer.limit()));
|
|
|
copyBytes(buffer, ioBuffer);
|
|
|
ioBuffer.flip();
|
|
|
int bytesWritten;
|
|
@@ -318,6 +323,7 @@ public abstract class SocketChannelContext extends ChannelContext<SocketChannel>
|
|
|
int totalBytesFlushed = 0;
|
|
|
while (continueFlush) {
|
|
|
ioBuffer.clear();
|
|
|
+ ioBuffer.limit(Math.min(WRITE_LIMIT, ioBuffer.limit()));
|
|
|
int j = 0;
|
|
|
ByteBuffer[] buffers = flushOperation.getBuffersToWrite();
|
|
|
while (j < buffers.length && ioBuffer.remaining() > 0) {
|