Removed the lock aquisition against SocketChannel when isConnected() and isBound() is called, because it causes unnecessary contention
This commit is contained in:
parent
c8fc3a1135
commit
60d3502ba1
@ -45,6 +45,7 @@ final class NioAcceptedSocketChannel extends NioSocketChannel {
|
||||
|
||||
this.bossThread = bossThread;
|
||||
|
||||
setConnected();
|
||||
fireChannelOpen(this);
|
||||
fireChannelBound(this, getLocalAddress());
|
||||
fireChannelConnected(this, getRemoteAddress());
|
||||
|
@ -124,6 +124,7 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
||||
try {
|
||||
channel.socket.socket().bind(localAddress);
|
||||
channel.boundManually = true;
|
||||
channel.setBound();
|
||||
future.setSuccess();
|
||||
fireChannelBound(channel, channel.getLocalAddress());
|
||||
} catch (Throwable t) {
|
||||
|
@ -45,6 +45,12 @@ import org.jboss.netty.util.internal.ThreadLocalBoolean;
|
||||
class NioSocketChannel extends AbstractChannel
|
||||
implements org.jboss.netty.channel.socket.SocketChannel {
|
||||
|
||||
private static final int ST_OPEN = 0;
|
||||
private static final int ST_BOUND = 1;
|
||||
private static final int ST_CONNECTED = 2;
|
||||
private static final int ST_CLOSED = -1;
|
||||
private volatile int state = ST_OPEN;
|
||||
|
||||
final SocketChannel socket;
|
||||
final NioWorker worker;
|
||||
private final NioSocketChannelConfig config;
|
||||
@ -108,12 +114,33 @@ class NioSocketChannel extends AbstractChannel
|
||||
return remoteAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return state >= ST_OPEN;
|
||||
}
|
||||
|
||||
public boolean isBound() {
|
||||
return isOpen() && socket.socket().isBound();
|
||||
return state >= ST_BOUND;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return isOpen() && socket.isConnected();
|
||||
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
|
||||
protected boolean setClosed() {
|
||||
state = ST_CLOSED;
|
||||
return super.setClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -155,11 +182,6 @@ class NioSocketChannel extends AbstractChannel
|
||||
super.setInterestOpsNow(interestOps);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setClosed() {
|
||||
return super.setClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelFuture write(Object message, SocketAddress remoteAddress) {
|
||||
if (remoteAddress == null || remoteAddress.equals(getRemoteAddress())) {
|
||||
|
@ -772,6 +772,7 @@ class NioWorker implements Runnable {
|
||||
}
|
||||
|
||||
if (!server) {
|
||||
channel.setConnected();
|
||||
if (!((NioClientSocketChannel) channel).boundManually) {
|
||||
fireChannelBound(channel, localAddress);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user