Add a boolean parameter to Channel.Unsafe.flush() so that SelectionKey state check can be bypassed.

This commit is contained in:
Trustin Lee 2013-07-12 20:14:50 +09:00
parent e10e9d38c4
commit 99716993f6
5 changed files with 8 additions and 8 deletions

View File

@ -592,12 +592,12 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
}
@Override
public void flush() {
public void flush(boolean force) {
outboundBuffer.addFlush();
flush0();
flush0(force);
}
private void flush0() {
private void flush0(boolean force) {
if (inFlushNow) {
// Avoid re-entrance
return;
@ -606,7 +606,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
// Flush immediately only when there's no pending flush.
// If there's a pending flush operation, event loop will call flushNow() later,
// and thus there's no need to call it now.
if (isFlushPending()) {
if (!force || isFlushPending()) {
return;
}

View File

@ -84,7 +84,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
}
@Override
public void flush() {
public void flush(boolean force) {
// ignore
}

View File

@ -242,7 +242,7 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelPr
/**
* Flush out all write operations scheduled via {@link #write(Object, ChannelPromise)}.
*/
void flush();
void flush(boolean force);
/**
* Return a special ChannelPromise which can be reused and passed to the operations in {@link Unsafe}.

View File

@ -1030,7 +1030,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
unsafe.flush();
unsafe.flush(false);
}
@Override

View File

@ -529,7 +529,7 @@ public final class NioEventLoop extends SingleThreadEventLoop {
}
// Call flushNow which will also take care of clear the OP_WRITE once there is nothing left to write
ch.unsafe().flush();
ch.unsafe().flush(true);
}
private static void unregisterWritableTasks(AbstractNioChannel ch) {