Motivation: If there are no readable bytes, it's unnecessary to go through javaChannel().write().

Modification:
If the readableBytes() is zero, then just return.

Result:
The logic can be easy to understand and a little faster than before.
This commit is contained in:
JongYoon Lim 2015-04-08 15:05:07 +09:00 committed by Norman Maurer
parent 28bd5a55c8
commit 30b711cf3d

View File

@ -174,6 +174,9 @@ public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel imp
final ByteBuf byteBuf = message.content(); final ByteBuf byteBuf = message.content();
final int messageSize = byteBuf.readableBytes(); final int messageSize = byteBuf.readableBytes();
if (messageSize == 0) {
return true;
}
final long writtenBytes; final long writtenBytes;
if (byteBuf.nioBufferCount() == 1) { if (byteBuf.nioBufferCount() == 1) {
@ -182,18 +185,13 @@ public class NioUdtMessageConnectorChannel extends AbstractNioMessageChannel imp
writtenBytes = javaChannel().write(byteBuf.nioBuffers()); writtenBytes = javaChannel().write(byteBuf.nioBuffers());
} }
// did not write the message
if (writtenBytes <= 0 && messageSize > 0) {
return false;
}
// wrote message completely // wrote message completely
if (writtenBytes != messageSize) { if (writtenBytes > 0 && writtenBytes != messageSize) {
throw new Error( throw new Error(
"Provider error: failed to write message. Provider library should be upgraded."); "Provider error: failed to write message. Provider library should be upgraded.");
} }
return true; return writtenBytes > 0;
} }
@Override @Override