From c165a38e15c93a0b8345aa46c678cc6cbb5d4fa6 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 13 Jun 2012 22:24:32 +0200 Subject: [PATCH] Revert as it should be in nio2 branch "Commit first round of classes to support nio2/async channel api. Still work in progress.. See #396" This reverts commit 18aaae3c2e7462853298c991c7f95040e47dae96. --- pom.xml | 4 ++- .../io/netty/channel/AbstractChannel.java | 30 +++++++++---------- .../netty/channel/AbstractServerChannel.java | 2 +- .../channel/embedded/EmbeddedByteChannel.java | 3 +- .../socket/nio/AbstractNioByteChannel.java | 5 ++-- .../socket/oio/AbstractOioByteChannel.java | 3 +- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 98da41cd56..20ef2a7f56 100644 --- a/pom.xml +++ b/pom.xml @@ -276,12 +276,14 @@ sun.misc.Unsafe java.util.zip.Deflater + java.nio.channels.DatagramChannel java.nio.channels.MembershipKey java.net.StandardSocketOptions java.net.StandardProtocolFamily - + + java.nio.channels.AsynchronousChannel java.nio.channels.AsynchronousSocketChannel java.nio.channels.AsynchronousServerSocketChannel diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index 98d7fb7aff..42890f3c8b 100755 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -85,7 +85,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha private ClosedChannelException closedChannelException; private final Deque flushCheckpoints = new ArrayDeque(); private long writeCounter; - protected boolean inFlushNow; + private boolean inFlushNow; private boolean flushNowPending; /** Cache for the string representation of this channel */ @@ -623,7 +623,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha } @Override - public void flushNow() { + public final void flushNow() { if (inFlushNow) { return; } @@ -631,13 +631,12 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha inFlushNow = true; ChannelHandlerContext ctx = directOutboundContext(); Throwable cause = null; - boolean handleFlush = true; try { if (ctx.hasOutboundByteBuffer()) { ByteBuf out = ctx.outboundByteBuffer(); int oldSize = out.readableBytes(); try { - handleFlush = doFlushByteBuffer(out); + doFlushByteBuffer(out); } catch (Throwable t) { cause = t; } finally { @@ -658,15 +657,14 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha writeCounter += oldSize - out.size(); } } - if (handleFlush) { - if (cause == null) { - notifyFlushFutures(); - } else { - notifyFlushFutures(cause); - pipeline.fireExceptionCaught(cause); - if (cause instanceof IOException) { - close(voidFuture()); - } + + if (cause == null) { + notifyFlushFutures(); + } else { + notifyFlushFutures(cause); + pipeline.fireExceptionCaught(cause); + if (cause instanceof IOException) { + close(voidFuture()); } } } finally { @@ -715,7 +713,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha protected abstract void doClose() throws Exception; protected abstract void doDeregister() throws Exception; - protected boolean doFlushByteBuffer(ByteBuf buf) throws Exception { + protected void doFlushByteBuffer(ByteBuf buf) throws Exception { throw new UnsupportedOperationException(); } protected void doFlushMessageBuffer(MessageBuf buf) throws Exception { @@ -724,7 +722,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha protected abstract boolean isFlushPending(); - protected final void notifyFlushFutures() { + private void notifyFlushFutures() { if (flushCheckpoints.isEmpty()) { return; } @@ -762,7 +760,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha } } - protected final void notifyFlushFutures(Throwable cause) { + private void notifyFlushFutures(Throwable cause) { notifyFlushFutures(); for (;;) { FlushCheckpoint cp = flushCheckpoints.poll(); diff --git a/transport/src/main/java/io/netty/channel/AbstractServerChannel.java b/transport/src/main/java/io/netty/channel/AbstractServerChannel.java index 6ac92e60b3..0c42167eeb 100755 --- a/transport/src/main/java/io/netty/channel/AbstractServerChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractServerChannel.java @@ -77,7 +77,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S } @Override - protected boolean doFlushByteBuffer(ByteBuf buf) throws Exception { + protected void doFlushByteBuffer(ByteBuf buf) throws Exception { throw new UnsupportedOperationException(); } diff --git a/transport/src/main/java/io/netty/channel/embedded/EmbeddedByteChannel.java b/transport/src/main/java/io/netty/channel/embedded/EmbeddedByteChannel.java index 8c1f7e3499..07e8ac5313 100755 --- a/transport/src/main/java/io/netty/channel/embedded/EmbeddedByteChannel.java +++ b/transport/src/main/java/io/netty/channel/embedded/EmbeddedByteChannel.java @@ -71,11 +71,10 @@ public class EmbeddedByteChannel extends AbstractEmbeddedChannel { } @Override - protected boolean doFlushByteBuffer(ByteBuf buf) throws Exception { + protected void doFlushByteBuffer(ByteBuf buf) throws Exception { if (!lastOutboundBuffer().readable()) { lastOutboundBuffer().discardReadBytes(); } lastOutboundBuffer().writeBytes(buf); - return true; } } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioByteChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioByteChannel.java index 99489e3ae7..fded47226c 100755 --- a/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/AbstractNioByteChannel.java @@ -85,11 +85,11 @@ abstract class AbstractNioByteChannel extends AbstractNioChannel { } @Override - protected boolean doFlushByteBuffer(ByteBuf buf) throws Exception { + protected void doFlushByteBuffer(ByteBuf buf) throws Exception { if (!buf.readable()) { // Reset reader/writerIndex to 0 if the buffer is empty. buf.clear(); - return true; + return; } for (int i = config().getWriteSpinCount() - 1; i >= 0; i --) { @@ -103,7 +103,6 @@ abstract class AbstractNioByteChannel extends AbstractNioChannel { break; } } - return true; } protected abstract int doReadBytes(ByteBuf buf) throws Exception; diff --git a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java index 563286b3b9..12697f74aa 100755 --- a/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/oio/AbstractOioByteChannel.java @@ -86,12 +86,11 @@ abstract class AbstractOioByteChannel extends AbstractOioChannel { } @Override - protected boolean doFlushByteBuffer(ByteBuf buf) throws Exception { + protected void doFlushByteBuffer(ByteBuf buf) throws Exception { while (buf.readable()) { doWriteBytes(buf); } buf.clear(); - return true; } protected abstract int available();