From 6496d2dbc7badfb586999ea63ff6bc66d76b100a Mon Sep 17 00:00:00 2001 From: JongYoon Lim Date: Wed, 8 Apr 2015 15:05:07 +0900 Subject: [PATCH] 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. --- .../udt/nio/NioUdtMessageConnectorChannel.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java index 55cd180e4a32..df51947f543f 100644 --- a/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java +++ b/transport-udt/src/main/java/io/netty/channel/udt/nio/NioUdtMessageConnectorChannel.java @@ -174,6 +174,9 @@ protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Ex final ByteBuf byteBuf = message.content(); final int messageSize = byteBuf.readableBytes(); + if (messageSize == 0) { + return true; + } final long writtenBytes; if (byteBuf.nioBufferCount() == 1) { @@ -182,18 +185,13 @@ protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Ex writtenBytes = javaChannel().write(byteBuf.nioBuffers()); } - // did not write the message - if (writtenBytes <= 0 && messageSize > 0) { - return false; - } - // wrote message completely - if (writtenBytes != messageSize) { + if (writtenBytes > 0 && writtenBytes != messageSize) { throw new Error( "Provider error: failed to write message. Provider library should be upgraded."); } - return true; + return writtenBytes > 0; } @Override