Reverted back previous check-in related with state update, which seems unnecessary

This commit is contained in:
Trustin Lee 2010-01-09 08:21:28 +00:00
parent 0acffadd29
commit 4ef936bea1
4 changed files with 34 additions and 34 deletions

View File

@ -45,7 +45,7 @@ final class NioAcceptedSocketChannel extends NioSocketChannel {
this.bossThread = bossThread; this.bossThread = bossThread;
state = NioSocketChannel.ST_CONNECTED; setConnected();
fireChannelOpen(this); fireChannelOpen(this);
fireChannelBound(this, getLocalAddress()); fireChannelBound(this, getLocalAddress());
fireChannelConnected(this, getRemoteAddress()); fireChannelConnected(this, getRemoteAddress());

View File

@ -124,7 +124,7 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
try { try {
channel.socket.socket().bind(localAddress); channel.socket.socket().bind(localAddress);
channel.boundManually = true; channel.boundManually = true;
channel.state = NioSocketChannel.ST_BOUND; channel.setBound();
future.setSuccess(); future.setSuccess();
fireChannelBound(channel, channel.getLocalAddress()); fireChannelBound(channel, channel.getLocalAddress());
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -45,11 +45,11 @@ import org.jboss.netty.util.internal.ThreadLocalBoolean;
class NioSocketChannel extends AbstractChannel class NioSocketChannel extends AbstractChannel
implements org.jboss.netty.channel.socket.SocketChannel { implements org.jboss.netty.channel.socket.SocketChannel {
static final int ST_OPEN = 0; private static final int ST_OPEN = 0;
static final int ST_BOUND = 1; private static final int ST_BOUND = 1;
static final int ST_CONNECTED = 2; private static final int ST_CONNECTED = 2;
static final int ST_CLOSED = -1; private static final int ST_CLOSED = -1;
volatile int state = ST_OPEN; private volatile int state = ST_OPEN;
final SocketChannel socket; final SocketChannel socket;
final NioWorker worker; final NioWorker worker;
@ -127,6 +127,16 @@ class NioSocketChannel extends AbstractChannel
return state == ST_CONNECTED; return state == ST_CONNECTED;
} }
final void setBound() {
assert state == ST_OPEN;
state = ST_BOUND;
}
final void setConnected() {
assert state == ST_OPEN || state == ST_BOUND;
state = ST_CONNECTED;
}
@Override @Override
protected boolean setClosed() { protected boolean setClosed() {
state = ST_CLOSED; state = ST_CLOSED;

View File

@ -23,6 +23,7 @@ import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.CancelledKeyException; import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException; import java.nio.channels.NotYetConnectedException;
import java.nio.channels.ScatteringByteChannel;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.Selector; import java.nio.channels.Selector;
import java.util.Iterator; import java.util.Iterator;
@ -302,8 +303,7 @@ class NioWorker implements Runnable {
} }
private static boolean read(SelectionKey k) { private static boolean read(SelectionKey k) {
java.nio.channels.SocketChannel ch = ScatteringByteChannel ch = (ScatteringByteChannel) k.channel();
(java.nio.channels.SocketChannel) k.channel();
NioSocketChannel channel = (NioSocketChannel) k.attachment(); NioSocketChannel channel = (NioSocketChannel) k.attachment();
ReceiveBufferSizePredictor predictor = ReceiveBufferSizePredictor predictor =
@ -325,16 +325,11 @@ class NioWorker implements Runnable {
} }
} }
failure = false; failure = false;
} catch (Throwable t) { } catch (AsynchronousCloseException e) {
if (!ch.isConnected()) {
channel.state = NioSocketChannel.ST_CLOSED;
}
if (t instanceof AsynchronousCloseException) {
// Can happen, and does not need a user attention. // Can happen, and does not need a user attention.
} else { } catch (Throwable t) {
fireExceptionCaught(channel, t); fireExceptionCaught(channel, t);
} }
}
if (readBytes > 0) { if (readBytes > 0) {
// Update the predictor. // Update the predictor.
@ -473,15 +468,11 @@ class NioWorker implements Runnable {
addOpWrite = true; addOpWrite = true;
break; break;
} }
} catch (Throwable t) { } catch (AsynchronousCloseException e) {
if (!channel.socket.isConnected()) {
channel.state = NioSocketChannel.ST_CLOSED;
}
if (t instanceof AsynchronousCloseException) {
// Doesn't need a user attention - ignore. // Doesn't need a user attention - ignore.
channel.currentWriteEvent = evt; channel.currentWriteEvent = evt;
channel.currentWriteIndex = bufIdx; channel.currentWriteIndex = bufIdx;
} else { } catch (Throwable t) {
channel.currentWriteEvent = null; channel.currentWriteEvent = null;
evt.getFuture().setFailure(t); evt.getFuture().setFailure(t);
evt = null; evt = null;
@ -492,7 +483,6 @@ class NioWorker implements Runnable {
} }
} }
} }
}
channel.inWriteNowLoop = false; channel.inWriteNowLoop = false;
} }
@ -782,7 +772,7 @@ class NioWorker implements Runnable {
} }
if (!server) { if (!server) {
channel.state = NioSocketChannel.ST_CONNECTED; channel.setConnected();
if (!((NioClientSocketChannel) channel).boundManually) { if (!((NioClientSocketChannel) channel).boundManually) {
fireChannelBound(channel, localAddress); fireChannelBound(channel, localAddress);
} }