Skip to content

Commit

Permalink
Motivation: If there are no readable bytes, it's unnecessary to go th…
Browse files Browse the repository at this point in the history
…rough 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.
  • Loading branch information
JongYoon Lim authored and normanmaurer committed Apr 8, 2015
1 parent 83ce8a9 commit 6496d2d
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 6496d2d

Please sign in to comment.