Do not write an empty buffer unnecessarily when nextChunk() returned

null
This commit is contained in:
Trustin Lee 2011-03-03 01:32:27 +09:00
parent a5e9f633ef
commit 98b2b6d8dc

View File

@ -226,34 +226,34 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
break; break;
} }
ChannelFuture writeFuture;
if (endOfInput) {
this.currentEvent = null;
closeInput(chunks);
writeFuture = currentEvent.getFuture();
} else {
writeFuture = future(channel);
writeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future)
throws Exception {
if (!future.isSuccess()) {
currentEvent.getFuture().setFailure(future.getCause());
closeInput((ChunkedInput) currentEvent.getMessage());
}
}
});
}
Channels.write(
ctx, writeFuture, chunk,
currentEvent.getRemoteAddress());
if (suspend) { if (suspend) {
// ChunkedInput.nextChunk() returned null and it has // ChunkedInput.nextChunk() returned null and it has
// not reached at the end of input. Let's wait until // not reached at the end of input. Let's wait until
// more chunks arrive. // more chunks arrive. Nothing to write or notify.
break; break;
} else {
ChannelFuture writeFuture;
if (endOfInput) {
this.currentEvent = null;
closeInput(chunks);
writeFuture = currentEvent.getFuture();
} else {
writeFuture = future(channel);
writeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future)
throws Exception {
if (!future.isSuccess()) {
currentEvent.getFuture().setFailure(future.getCause());
closeInput((ChunkedInput) currentEvent.getMessage());
}
}
});
}
Channels.write(
ctx, writeFuture, chunk,
currentEvent.getRemoteAddress());
} }
} else { } else {
this.currentEvent = null; this.currentEvent = null;