Make ChannelConfig.setAutoRead() triggers Channel.read() if autoRead was previously false

- also rename JDK socket and channel variables so that they are less ambiguous
This commit is contained in:
Trustin Lee 2013-01-01 16:49:21 +09:00
parent 218afba1f2
commit 103edc4467
25 changed files with 163 additions and 144 deletions

View File

@ -22,7 +22,6 @@ import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundByteHandlerAdapter;
import io.netty.channel.ChannelOption;
import org.junit.Ignore;
import org.junit.Test;
import java.net.Socket;
@ -38,7 +37,7 @@ public class ServerSocketSuspendTest extends AbstractServerSocketTest {
private static final long TIMEOUT = 3000000000L;
@Test
@Ignore("Need to investigate why it fails on osx")
//@Ignore("Need to investigate why it fails on osx")
public void testSuspendAndResumeAccept() throws Throwable {
run();
}
@ -63,7 +62,6 @@ public class ServerSocketSuspendTest extends AbstractServerSocketTest {
}
sc.config().setAutoRead(true);
sc.read();
counter.latch.await();

View File

@ -33,11 +33,20 @@ public class DefaultChannelConfig implements ChannelConfig {
private static final ByteBufAllocator DEFAULT_ALLOCATOR = PooledByteBufAllocator.DEFAULT;
private static final int DEFAULT_CONNECT_TIMEOUT = 30000;
protected final Channel channel;
private volatile ByteBufAllocator allocator = DEFAULT_ALLOCATOR;
private volatile int connectTimeoutMillis = DEFAULT_CONNECT_TIMEOUT;
private volatile int writeSpinCount = 16;
private volatile boolean autoRead = true;
public DefaultChannelConfig(Channel channel) {
if (channel == null) {
throw new NullPointerException("channel");
}
this.channel = channel;
}
@Override
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(null, CONNECT_TIMEOUT_MILLIS, WRITE_SPIN_COUNT, ALLOCATOR, AUTO_READ);
@ -171,7 +180,11 @@ public class DefaultChannelConfig implements ChannelConfig {
@Override
public ChannelConfig setAutoRead(boolean autoRead) {
boolean oldAutoRead = this.autoRead;
this.autoRead = autoRead;
if (autoRead && !oldAutoRead) {
channel.read();
}
return this;
}
}

View File

@ -48,7 +48,7 @@ public abstract class AbstractEmbeddedChannel<O> extends AbstractChannel {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractEmbeddedChannel.class);
private final EmbeddedEventLoop loop = new EmbeddedEventLoop();
private final ChannelConfig config = new DefaultChannelConfig();
private final ChannelConfig config = new DefaultChannelConfig(this);
private final SocketAddress localAddress = new EmbeddedSocketAddress();
private final SocketAddress remoteAddress = new EmbeddedSocketAddress();
private final MessageBuf<Object> lastInboundMessageBuffer = Unpooled.messageBuffer();

View File

@ -43,7 +43,7 @@ public class LocalChannel extends AbstractChannel {
private static final ChannelMetadata METADATA = new ChannelMetadata(BufType.MESSAGE, false);
private final ChannelConfig config = new DefaultChannelConfig();
private final ChannelConfig config = new DefaultChannelConfig(this);
private final Runnable shutdownHook = new Runnable() {
@Override
public void run() {

View File

@ -32,7 +32,7 @@ import java.net.SocketAddress;
*/
public class LocalServerChannel extends AbstractServerChannel {
private final ChannelConfig config = new DefaultChannelConfig();
private final ChannelConfig config = new DefaultChannelConfig(this);
private final Runnable shutdownHook = new Runnable() {
@Override
public void run() {

View File

@ -42,17 +42,18 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
private static final int DEFAULT_RECEIVE_PACKET_SIZE = 2048;
private final DatagramSocket socket;
private final DatagramSocket javaSocket;
private volatile int receivePacketSize = DEFAULT_RECEIVE_PACKET_SIZE;
/**
* Creates a new instance.
*/
public DefaultDatagramChannelConfig(DatagramSocket socket) {
if (socket == null) {
throw new NullPointerException("socket");
public DefaultDatagramChannelConfig(DatagramChannel channel, DatagramSocket javaSocket) {
super(channel);
if (javaSocket == null) {
throw new NullPointerException("javaSocket");
}
this.socket = socket;
this.javaSocket = javaSocket;
}
@Override
@ -134,7 +135,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public boolean isBroadcast() {
try {
return socket.getBroadcast();
return javaSocket.getBroadcast();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -146,17 +147,17 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
// See: https://github.com/netty/netty/issues/576
if (broadcast &&
!DetectionUtil.isWindows() && !DetectionUtil.isRoot() &&
!socket.getLocalAddress().isAnyLocalAddress()) {
!javaSocket.getLocalAddress().isAnyLocalAddress()) {
// Warn a user about the fact that a non-root user can't receive a
// broadcast packet on *nix if the socket is bound on non-wildcard address.
logger.warn(
"A non-root user can't receive a broadcast packet if the socket " +
"is not bound to a wildcard address; setting the SO_BROADCAST flag " +
"anyway as requested on the socket which is bound to " +
socket.getLocalSocketAddress() + '.');
javaSocket.getLocalSocketAddress() + '.');
}
socket.setBroadcast(broadcast);
javaSocket.setBroadcast(broadcast);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -165,9 +166,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public InetAddress getInterface() {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
return ((MulticastSocket) socket).getInterface();
return ((MulticastSocket) javaSocket).getInterface();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -178,9 +179,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setInterface(InetAddress interfaceAddress) {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
((MulticastSocket) socket).setInterface(interfaceAddress);
((MulticastSocket) javaSocket).setInterface(interfaceAddress);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -192,9 +193,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public boolean isLoopbackModeDisabled() {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
return ((MulticastSocket) socket).getLoopbackMode();
return ((MulticastSocket) javaSocket).getLoopbackMode();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -205,9 +206,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setLoopbackModeDisabled(boolean loopbackModeDisabled) {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
((MulticastSocket) socket).setLoopbackMode(loopbackModeDisabled);
((MulticastSocket) javaSocket).setLoopbackMode(loopbackModeDisabled);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -219,9 +220,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public NetworkInterface getNetworkInterface() {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
return ((MulticastSocket) socket).getNetworkInterface();
return ((MulticastSocket) javaSocket).getNetworkInterface();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -232,9 +233,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
((MulticastSocket) socket).setNetworkInterface(networkInterface);
((MulticastSocket) javaSocket).setNetworkInterface(networkInterface);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -247,7 +248,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public boolean isReuseAddress() {
try {
return socket.getReuseAddress();
return javaSocket.getReuseAddress();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -256,7 +257,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setReuseAddress(boolean reuseAddress) {
try {
socket.setReuseAddress(reuseAddress);
javaSocket.setReuseAddress(reuseAddress);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -266,7 +267,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public int getReceiveBufferSize() {
try {
return socket.getReceiveBufferSize();
return javaSocket.getReceiveBufferSize();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -275,7 +276,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setReceiveBufferSize(int receiveBufferSize) {
try {
socket.setReceiveBufferSize(receiveBufferSize);
javaSocket.setReceiveBufferSize(receiveBufferSize);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -285,7 +286,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public int getSendBufferSize() {
try {
return socket.getSendBufferSize();
return javaSocket.getSendBufferSize();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -294,7 +295,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setSendBufferSize(int sendBufferSize) {
try {
socket.setSendBufferSize(sendBufferSize);
javaSocket.setSendBufferSize(sendBufferSize);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -318,9 +319,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public int getTimeToLive() {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
return ((MulticastSocket) socket).getTimeToLive();
return ((MulticastSocket) javaSocket).getTimeToLive();
} catch (IOException e) {
throw new ChannelException(e);
}
@ -331,9 +332,9 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setTimeToLive(int ttl) {
if (socket instanceof MulticastSocket) {
if (javaSocket instanceof MulticastSocket) {
try {
((MulticastSocket) socket).setTimeToLive(ttl);
((MulticastSocket) javaSocket).setTimeToLive(ttl);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -346,7 +347,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public int getTrafficClass() {
try {
return socket.getTrafficClass();
return javaSocket.getTrafficClass();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -355,7 +356,7 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
@Override
public DatagramChannelConfig setTrafficClass(int trafficClass) {
try {
socket.setTrafficClass(trafficClass);
javaSocket.setTrafficClass(trafficClass);
} catch (SocketException e) {
throw new ChannelException(e);
}

View File

@ -32,13 +32,14 @@ import static io.netty.channel.ChannelOption.*;
*/
public class DefaultSctpChannelConfig extends DefaultChannelConfig implements SctpChannelConfig {
private final SctpChannel channel;
private final SctpChannel javaChannel;
public DefaultSctpChannelConfig(SctpChannel channel) {
if (channel == null) {
throw new NullPointerException("channel");
public DefaultSctpChannelConfig(io.netty.channel.socket.SctpChannel channel, SctpChannel javaChannel) {
super(channel);
if (javaChannel == null) {
throw new NullPointerException("javaChannel");
}
this.channel = channel;
this.javaChannel = javaChannel;
}
@Override
@ -85,7 +86,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public boolean isSctpNoDelay() {
try {
return channel.getOption(SctpStandardSocketOptions.SCTP_NODELAY);
return javaChannel.getOption(SctpStandardSocketOptions.SCTP_NODELAY);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -94,7 +95,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public SctpChannelConfig setSctpNoDelay(boolean sctpNoDelay) {
try {
channel.setOption(SctpStandardSocketOptions.SCTP_NODELAY, sctpNoDelay);
javaChannel.setOption(SctpStandardSocketOptions.SCTP_NODELAY, sctpNoDelay);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -104,7 +105,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public int getSendBufferSize() {
try {
return channel.getOption(SctpStandardSocketOptions.SO_SNDBUF);
return javaChannel.getOption(SctpStandardSocketOptions.SO_SNDBUF);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -113,7 +114,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public SctpChannelConfig setSendBufferSize(int sendBufferSize) {
try {
channel.setOption(SctpStandardSocketOptions.SO_SNDBUF, sendBufferSize);
javaChannel.setOption(SctpStandardSocketOptions.SO_SNDBUF, sendBufferSize);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -123,7 +124,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public int getReceiveBufferSize() {
try {
return channel.getOption(SctpStandardSocketOptions.SO_RCVBUF);
return javaChannel.getOption(SctpStandardSocketOptions.SO_RCVBUF);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -132,7 +133,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public SctpChannelConfig setReceiveBufferSize(int receiveBufferSize) {
try {
channel.setOption(SctpStandardSocketOptions.SO_RCVBUF, receiveBufferSize);
javaChannel.setOption(SctpStandardSocketOptions.SO_RCVBUF, receiveBufferSize);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -142,7 +143,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public SctpStandardSocketOptions.InitMaxStreams getInitMaxStreams() {
try {
return channel.getOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS);
return javaChannel.getOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -151,7 +152,7 @@ public class DefaultSctpChannelConfig extends DefaultChannelConfig implements Sc
@Override
public SctpChannelConfig setInitMaxStreams(SctpStandardSocketOptions.InitMaxStreams initMaxStreams) {
try {
channel.setOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, initMaxStreams);
javaChannel.setOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, initMaxStreams);
} catch (IOException e) {
throw new ChannelException(e);
}

View File

@ -16,7 +16,6 @@
package io.netty.channel.socket;
import com.sun.nio.sctp.SctpServerChannel;
import com.sun.nio.sctp.SctpStandardSocketOptions;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelOption;
@ -33,17 +32,19 @@ import static com.sun.nio.sctp.SctpStandardSocketOptions.*;
*/
public class DefaultSctpServerChannelConfig extends DefaultChannelConfig implements SctpServerChannelConfig {
private final SctpServerChannel serverChannel;
private final SctpServerChannel javaChannel;
private volatile int backlog = NetUtil.SOMAXCONN;
/**
* Creates a new instance.
*/
public DefaultSctpServerChannelConfig(SctpServerChannel serverChannel) {
if (serverChannel == null) {
throw new NullPointerException("serverChannel");
public DefaultSctpServerChannelConfig(
io.netty.channel.socket.SctpServerChannel channel, SctpServerChannel javaChannel) {
super(channel);
if (javaChannel == null) {
throw new NullPointerException("javaChannel");
}
this.serverChannel = serverChannel;
this.javaChannel = javaChannel;
}
@Override
@ -74,7 +75,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme
} else if (option == ChannelOption.SO_SNDBUF) {
setSendBufferSize((Integer) value);
} else if (option == ChannelOption.SCTP_INIT_MAXSTREAMS) {
setInitMaxStreams((SctpStandardSocketOptions.InitMaxStreams) value);
setInitMaxStreams((InitMaxStreams) value);
} else {
return super.setOption(option, value);
}
@ -85,7 +86,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme
@Override
public int getSendBufferSize() {
try {
return serverChannel.getOption(SO_SNDBUF);
return javaChannel.getOption(SO_SNDBUF);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -94,7 +95,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme
@Override
public SctpServerChannelConfig setSendBufferSize(int sendBufferSize) {
try {
serverChannel.setOption(SO_SNDBUF, sendBufferSize);
javaChannel.setOption(SO_SNDBUF, sendBufferSize);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -104,7 +105,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme
@Override
public int getReceiveBufferSize() {
try {
return serverChannel.getOption(SO_RCVBUF);
return javaChannel.getOption(SO_RCVBUF);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -113,7 +114,7 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme
@Override
public SctpServerChannelConfig setReceiveBufferSize(int receiveBufferSize) {
try {
serverChannel.setOption(SO_RCVBUF, receiveBufferSize);
javaChannel.setOption(SO_RCVBUF, receiveBufferSize);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -121,18 +122,18 @@ public class DefaultSctpServerChannelConfig extends DefaultChannelConfig impleme
}
@Override
public SctpStandardSocketOptions.InitMaxStreams getInitMaxStreams() {
public InitMaxStreams getInitMaxStreams() {
try {
return serverChannel.getOption(SCTP_INIT_MAXSTREAMS);
return javaChannel.getOption(SCTP_INIT_MAXSTREAMS);
} catch (IOException e) {
throw new ChannelException(e);
}
}
@Override
public SctpServerChannelConfig setInitMaxStreams(SctpStandardSocketOptions.InitMaxStreams initMaxStreams) {
public SctpServerChannelConfig setInitMaxStreams(InitMaxStreams initMaxStreams) {
try {
serverChannel.setOption(SCTP_INIT_MAXSTREAMS, initMaxStreams);
javaChannel.setOption(SCTP_INIT_MAXSTREAMS, initMaxStreams);
} catch (IOException e) {
throw new ChannelException(e);
}

View File

@ -33,17 +33,18 @@ import static io.netty.channel.ChannelOption.*;
public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
implements ServerSocketChannelConfig {
private final ServerSocket socket;
private final ServerSocket javaSocket;
private volatile int backlog = NetUtil.SOMAXCONN;
/**
* Creates a new instance.
*/
public DefaultServerSocketChannelConfig(ServerSocket socket) {
if (socket == null) {
throw new NullPointerException("socket");
public DefaultServerSocketChannelConfig(ServerSocketChannel channel, ServerSocket javaSocket) {
super(channel);
if (javaSocket == null) {
throw new NullPointerException("javaSocket");
}
this.socket = socket;
this.javaSocket = javaSocket;
}
@Override
@ -87,7 +88,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
@Override
public boolean isReuseAddress() {
try {
return socket.getReuseAddress();
return javaSocket.getReuseAddress();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -96,7 +97,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
@Override
public ServerSocketChannelConfig setReuseAddress(boolean reuseAddress) {
try {
socket.setReuseAddress(reuseAddress);
javaSocket.setReuseAddress(reuseAddress);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -106,7 +107,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
@Override
public int getReceiveBufferSize() {
try {
return socket.getReceiveBufferSize();
return javaSocket.getReceiveBufferSize();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -115,7 +116,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
@Override
public ServerSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
try {
socket.setReceiveBufferSize(receiveBufferSize);
javaSocket.setReceiveBufferSize(receiveBufferSize);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -124,7 +125,7 @@ public class DefaultServerSocketChannelConfig extends DefaultChannelConfig
@Override
public ServerSocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
socket.setPerformancePreferences(connectionTime, latency, bandwidth);
javaSocket.setPerformancePreferences(connectionTime, latency, bandwidth);
return this;
}

View File

@ -32,17 +32,18 @@ import static io.netty.channel.ChannelOption.*;
public class DefaultSocketChannelConfig extends DefaultChannelConfig
implements SocketChannelConfig {
private final Socket socket;
private final Socket javaSocket;
private volatile boolean allowHalfClosure;
/**
* Creates a new instance.
*/
public DefaultSocketChannelConfig(Socket socket) {
if (socket == null) {
throw new NullPointerException("socket");
public DefaultSocketChannelConfig(SocketChannel channel, Socket javaSocket) {
super(channel);
if (javaSocket == null) {
throw new NullPointerException("javaSocket");
}
this.socket = socket;
this.javaSocket = javaSocket;
}
@Override
@ -114,7 +115,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public int getReceiveBufferSize() {
try {
return socket.getReceiveBufferSize();
return javaSocket.getReceiveBufferSize();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -123,7 +124,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public int getSendBufferSize() {
try {
return socket.getSendBufferSize();
return javaSocket.getSendBufferSize();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -132,7 +133,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public int getSoLinger() {
try {
return socket.getSoLinger();
return javaSocket.getSoLinger();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -141,7 +142,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public int getTrafficClass() {
try {
return socket.getTrafficClass();
return javaSocket.getTrafficClass();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -150,7 +151,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public boolean isKeepAlive() {
try {
return socket.getKeepAlive();
return javaSocket.getKeepAlive();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -159,7 +160,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public boolean isReuseAddress() {
try {
return socket.getReuseAddress();
return javaSocket.getReuseAddress();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -168,7 +169,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public boolean isTcpNoDelay() {
try {
return socket.getTcpNoDelay();
return javaSocket.getTcpNoDelay();
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -177,7 +178,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public SocketChannelConfig setKeepAlive(boolean keepAlive) {
try {
socket.setKeepAlive(keepAlive);
javaSocket.setKeepAlive(keepAlive);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -187,14 +188,14 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public SocketChannelConfig setPerformancePreferences(
int connectionTime, int latency, int bandwidth) {
socket.setPerformancePreferences(connectionTime, latency, bandwidth);
javaSocket.setPerformancePreferences(connectionTime, latency, bandwidth);
return this;
}
@Override
public SocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
try {
socket.setReceiveBufferSize(receiveBufferSize);
javaSocket.setReceiveBufferSize(receiveBufferSize);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -204,7 +205,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public SocketChannelConfig setReuseAddress(boolean reuseAddress) {
try {
socket.setReuseAddress(reuseAddress);
javaSocket.setReuseAddress(reuseAddress);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -214,7 +215,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public SocketChannelConfig setSendBufferSize(int sendBufferSize) {
try {
socket.setSendBufferSize(sendBufferSize);
javaSocket.setSendBufferSize(sendBufferSize);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -225,9 +226,9 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
public SocketChannelConfig setSoLinger(int soLinger) {
try {
if (soLinger < 0) {
socket.setSoLinger(false, 0);
javaSocket.setSoLinger(false, 0);
} else {
socket.setSoLinger(true, soLinger);
javaSocket.setSoLinger(true, soLinger);
}
} catch (SocketException e) {
throw new ChannelException(e);
@ -238,7 +239,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public SocketChannelConfig setTcpNoDelay(boolean tcpNoDelay) {
try {
socket.setTcpNoDelay(tcpNoDelay);
javaSocket.setTcpNoDelay(tcpNoDelay);
} catch (SocketException e) {
throw new ChannelException(e);
}
@ -248,7 +249,7 @@ public class DefaultSocketChannelConfig extends DefaultChannelConfig
@Override
public SocketChannelConfig setTrafficClass(int trafficClass) {
try {
socket.setTrafficClass(trafficClass);
javaSocket.setTrafficClass(trafficClass);
} catch (SocketException e) {
throw new ChannelException(e);
}

View File

@ -64,7 +64,7 @@ public class AioServerSocketChannel extends AbstractAioChannel implements Server
*/
public AioServerSocketChannel() {
super(null, null, null);
config = new AioServerSocketChannelConfig();
config = new AioServerSocketChannelConfig(this);
}
/**
@ -74,7 +74,7 @@ public class AioServerSocketChannel extends AbstractAioChannel implements Server
*/
public AioServerSocketChannel(AsynchronousServerSocketChannel channel) {
super(null, null, channel);
config = new AioServerSocketChannelConfig(channel);
config = new AioServerSocketChannelConfig(this, channel);
}
@Override

View File

@ -38,7 +38,7 @@ import static io.netty.channel.ChannelOption.*;
final class AioServerSocketChannelConfig extends DefaultChannelConfig
implements ServerSocketChannelConfig {
private final AtomicReference<AsynchronousServerSocketChannel> channel
private final AtomicReference<AsynchronousServerSocketChannel> javaChannel
= new AtomicReference<AsynchronousServerSocketChannel>();
private volatile int backlog = NetUtil.SOMAXCONN;
private Map<SocketOption<?>, Object> options = new ConcurrentHashMap<SocketOption<?>, Object>();
@ -51,14 +51,16 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
* You should call {@link #assign(AsynchronousServerSocketChannel)} to assign a
* {@link AsynchronousServerSocketChannel} to it and have the configuration set on it.
*/
AioServerSocketChannelConfig() {
AioServerSocketChannelConfig(AioServerSocketChannel channel) {
super(channel);
}
/**
* Creates a new instance with the given {@link AsynchronousServerSocketChannel} assigned to it.
*/
AioServerSocketChannelConfig(AsynchronousServerSocketChannel channel) {
this.channel.set(channel);
AioServerSocketChannelConfig(AioServerSocketChannel channel, AsynchronousServerSocketChannel javaChannel) {
super(channel);
this.javaChannel.set(javaChannel);
}
@Override
@ -142,7 +144,7 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object getOption(SocketOption option, Object defaultValue) {
if (channel.get() == null) {
if (javaChannel.get() == null) {
Object value = options.get(option);
if (value == null) {
return defaultValue;
@ -152,7 +154,7 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
}
try {
return channel.get().getOption(option);
return javaChannel.get().getOption(option);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -160,12 +162,12 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
@SuppressWarnings({ "unchecked", "rawtypes" })
private void setOption(SocketOption option, Object defaultValue) {
if (channel.get() == null) {
if (javaChannel.get() == null) {
options.put(option, defaultValue);
return;
}
try {
channel.get().setOption(option, defaultValue);
javaChannel.get().setOption(option, defaultValue);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -174,11 +176,11 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
/**
* Assing the given {@link AsynchronousServerSocketChannel} to this instance
*/
void assign(AsynchronousServerSocketChannel channel) {
if (channel == null) {
throw new NullPointerException("channel");
void assign(AsynchronousServerSocketChannel javaChannel) {
if (javaChannel == null) {
throw new NullPointerException("javaChannel");
}
if (this.channel.compareAndSet(null, channel)) {
if (this.javaChannel.compareAndSet(null, javaChannel)) {
propagateOptions();
}
}
@ -189,7 +191,7 @@ final class AioServerSocketChannelConfig extends DefaultChannelConfig
Object value = options.remove(option);
if (value != null) {
try {
channel.get().setOption(option, value);
javaChannel.get().setOption(option, value);
} catch (IOException e) {
throw new ChannelException(e);
}

View File

@ -98,7 +98,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
AioSocketChannel(
AioServerSocketChannel parent, Integer id, AsynchronousSocketChannel ch) {
super(parent, id, ch);
config = new DefaultAioSocketChannelConfig(ch);
config = new DefaultAioSocketChannelConfig(this, ch);
}
@Override

View File

@ -36,7 +36,7 @@ import static io.netty.channel.ChannelOption.*;
final class DefaultAioSocketChannelConfig extends DefaultChannelConfig
implements AioSocketChannelConfig {
private final AtomicReference<NetworkChannel> channel = new AtomicReference<NetworkChannel>();
private final AtomicReference<NetworkChannel> javaChannel = new AtomicReference<NetworkChannel>();
private volatile boolean allowHalfClosure;
private volatile long readTimeoutInMillis;
private volatile long writeTimeoutInMillis;
@ -55,14 +55,16 @@ final class DefaultAioSocketChannelConfig extends DefaultChannelConfig
* You should call {@link #assign(NetworkChannel)} to assign a {@link NetworkChannel} to it and
* have the configuration set on it.
*/
DefaultAioSocketChannelConfig() {
DefaultAioSocketChannelConfig(AioSocketChannel channel) {
super(channel);
}
/**
* Creates a new instance with the given {@link NetworkChannel} assigned to it.
*/
DefaultAioSocketChannelConfig(NetworkChannel channel) {
this.channel.set(channel);
DefaultAioSocketChannelConfig(AioSocketChannel channel, NetworkChannel javaChannel) {
super(channel);
this.javaChannel.set(javaChannel);
}
@Override
@ -226,7 +228,7 @@ final class DefaultAioSocketChannelConfig extends DefaultChannelConfig
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object getOption(SocketOption option, Object defaultValue) {
if (channel.get() == null) {
if (javaChannel.get() == null) {
Object value = options.get(option);
if (value == null) {
return defaultValue;
@ -236,7 +238,7 @@ final class DefaultAioSocketChannelConfig extends DefaultChannelConfig
}
try {
return channel.get().getOption(option);
return javaChannel.get().getOption(option);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -244,12 +246,12 @@ final class DefaultAioSocketChannelConfig extends DefaultChannelConfig
@SuppressWarnings({ "unchecked", "rawtypes" })
private void setOption(SocketOption option, Object defaultValue) {
if (channel.get() == null) {
if (javaChannel.get() == null) {
options.put(option, defaultValue);
return;
}
try {
channel.get().setOption(option, defaultValue);
javaChannel.get().setOption(option, defaultValue);
} catch (IOException e) {
throw new ChannelException(e);
}
@ -297,11 +299,11 @@ final class DefaultAioSocketChannelConfig extends DefaultChannelConfig
/**
* Assing the given {@link NetworkChannel} to this instance
*/
void assign(NetworkChannel channel) {
if (channel == null) {
throw new NullPointerException("channel");
void assign(NetworkChannel javaChannel) {
if (javaChannel == null) {
throw new NullPointerException("javaChannel");
}
if (this.channel.compareAndSet(null, channel)) {
if (this.javaChannel.compareAndSet(null, javaChannel)) {
propagateOptions();
}
}
@ -312,7 +314,7 @@ final class DefaultAioSocketChannelConfig extends DefaultChannelConfig
Object value = options.remove(option);
if (value != null) {
try {
channel.get().setOption(option, value);
javaChannel.get().setOption(option, value);
} catch (IOException e) {
throw new ChannelException(e);
}

View File

@ -111,7 +111,7 @@ public final class NioDatagramChannel
*/
public NioDatagramChannel(Integer id, DatagramChannel socket) {
super(null, id, socket, SelectionKey.OP_READ);
config = new NioDatagramChannelConfig(socket);
config = new NioDatagramChannelConfig(this, socket);
}
@Override

View File

@ -15,7 +15,6 @@
*/
package io.netty.channel.socket.nio;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelException;
import io.netty.channel.socket.DatagramChannelConfig;
import io.netty.channel.socket.DefaultDatagramChannelConfig;
@ -98,11 +97,11 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
SET_OPTION = setOption;
}
private final DatagramChannel channel;
private final DatagramChannel javaChannel;
NioDatagramChannelConfig(DatagramChannel channel) {
super(channel.socket());
this.channel = channel;
NioDatagramChannelConfig(NioDatagramChannel channel, DatagramChannel javaChannel) {
super(channel, javaChannel.socket());
this.javaChannel = javaChannel;
}
@Override
@ -167,7 +166,7 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
throw new UnsupportedOperationException();
} else {
try {
return GET_OPTION.invoke(channel, option);
return GET_OPTION.invoke(javaChannel, option);
} catch (Exception e) {
throw new ChannelException(e);
}
@ -179,7 +178,7 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
throw new UnsupportedOperationException();
} else {
try {
SET_OPTION.invoke(channel, option, value);
SET_OPTION.invoke(javaChannel, option, value);
} catch (Exception e) {
throw new ChannelException(e);
}

View File

@ -97,7 +97,7 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
super(parent, id, sctpChannel, SelectionKey.OP_READ);
try {
sctpChannel.configureBlocking(false);
config = new DefaultSctpChannelConfig(sctpChannel);
config = new DefaultSctpChannelConfig(this, sctpChannel);
notificationHandler = new SctpNotificationHandler(this);
} catch (IOException e) {
try {

View File

@ -60,7 +60,7 @@ public class NioSctpServerChannel extends AbstractNioMessageChannel
*/
public NioSctpServerChannel() {
super(null, null, newSocket(), SelectionKey.OP_ACCEPT);
config = new DefaultSctpServerChannelConfig(javaChannel());
config = new DefaultSctpServerChannelConfig(this, javaChannel());
}
@Override

View File

@ -54,7 +54,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
*/
public NioServerSocketChannel() {
super(null, null, newSocket(), SelectionKey.OP_ACCEPT);
config = new DefaultServerSocketChannelConfig(javaChannel().socket());
config = new DefaultServerSocketChannelConfig(this, javaChannel().socket());
}
@Override

View File

@ -90,7 +90,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
throw new ChannelException("Failed to enter non-blocking mode.", e);
}
config = new DefaultSocketChannelConfig(socket.socket());
config = new DefaultSocketChannelConfig(this, socket.socket());
}
@Override

View File

@ -105,7 +105,7 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
}
this.socket = socket;
config = new DefaultDatagramChannelConfig(socket);
config = new DefaultDatagramChannelConfig(this, socket);
}
@Override

View File

@ -116,7 +116,7 @@ public class OioSctpChannel extends AbstractOioMessageChannel
ch.register(writeSelector, SelectionKey.OP_WRITE);
ch.register(connectSelector, SelectionKey.OP_CONNECT);
config = new DefaultSctpChannelConfig(ch);
config = new DefaultSctpChannelConfig(this, ch);
notificationHandler = new SctpNotificationHandler(this);
success = true;
} catch (Exception e) {

View File

@ -97,7 +97,7 @@ public class OioSctpServerChannel extends AbstractOioMessageChannel
sch.configureBlocking(false);
selector = Selector.open();
sch.register(selector, SelectionKey.OP_ACCEPT);
config = new DefaultSctpServerChannelConfig(sch);
config = new DefaultSctpServerChannelConfig(this, sch);
success = true;
} catch (Exception e) {
throw new ChannelException("failed to initialize a sctp server channel", e);

View File

@ -108,7 +108,7 @@ public class OioServerSocketChannel extends AbstractOioMessageChannel
}
this.socket = socket;
config = new DefaultServerSocketChannelConfig(socket);
config = new DefaultServerSocketChannelConfig(this, socket);
}
@Override

View File

@ -84,7 +84,7 @@ public class OioSocketChannel extends AbstractOioByteChannel
public OioSocketChannel(Channel parent, Integer id, Socket socket) {
super(parent, id);
this.socket = socket;
config = new DefaultSocketChannelConfig(socket);
config = new DefaultSocketChannelConfig(this, socket);
boolean success = false;
try {