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.ChannelHandlerContext;
import io.netty.channel.ChannelInboundByteHandlerAdapter; import io.netty.channel.ChannelInboundByteHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.net.Socket; import java.net.Socket;
@ -38,7 +37,7 @@ public class ServerSocketSuspendTest extends AbstractServerSocketTest {
private static final long TIMEOUT = 3000000000L; private static final long TIMEOUT = 3000000000L;
@Test @Test
@Ignore("Need to investigate why it fails on osx") //@Ignore("Need to investigate why it fails on osx")
public void testSuspendAndResumeAccept() throws Throwable { public void testSuspendAndResumeAccept() throws Throwable {
run(); run();
} }
@ -63,7 +62,6 @@ public class ServerSocketSuspendTest extends AbstractServerSocketTest {
} }
sc.config().setAutoRead(true); sc.config().setAutoRead(true);
sc.read();
counter.latch.await(); 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 ByteBufAllocator DEFAULT_ALLOCATOR = PooledByteBufAllocator.DEFAULT;
private static final int DEFAULT_CONNECT_TIMEOUT = 30000; private static final int DEFAULT_CONNECT_TIMEOUT = 30000;
protected final Channel channel;
private volatile ByteBufAllocator allocator = DEFAULT_ALLOCATOR; private volatile ByteBufAllocator allocator = DEFAULT_ALLOCATOR;
private volatile int connectTimeoutMillis = DEFAULT_CONNECT_TIMEOUT; private volatile int connectTimeoutMillis = DEFAULT_CONNECT_TIMEOUT;
private volatile int writeSpinCount = 16; private volatile int writeSpinCount = 16;
private volatile boolean autoRead = true; private volatile boolean autoRead = true;
public DefaultChannelConfig(Channel channel) {
if (channel == null) {
throw new NullPointerException("channel");
}
this.channel = channel;
}
@Override @Override
public Map<ChannelOption<?>, Object> getOptions() { public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(null, CONNECT_TIMEOUT_MILLIS, WRITE_SPIN_COUNT, ALLOCATOR, AUTO_READ); return getOptions(null, CONNECT_TIMEOUT_MILLIS, WRITE_SPIN_COUNT, ALLOCATOR, AUTO_READ);
@ -171,7 +180,11 @@ public class DefaultChannelConfig implements ChannelConfig {
@Override @Override
public ChannelConfig setAutoRead(boolean autoRead) { public ChannelConfig setAutoRead(boolean autoRead) {
boolean oldAutoRead = this.autoRead;
this.autoRead = autoRead; this.autoRead = autoRead;
if (autoRead && !oldAutoRead) {
channel.read();
}
return this; 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 static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractEmbeddedChannel.class);
private final EmbeddedEventLoop loop = new EmbeddedEventLoop(); 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 localAddress = new EmbeddedSocketAddress();
private final SocketAddress remoteAddress = new EmbeddedSocketAddress(); private final SocketAddress remoteAddress = new EmbeddedSocketAddress();
private final MessageBuf<Object> lastInboundMessageBuffer = Unpooled.messageBuffer(); 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 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() { private final Runnable shutdownHook = new Runnable() {
@Override @Override
public void run() { public void run() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,6 @@
*/ */
package io.netty.channel.socket.nio; package io.netty.channel.socket.nio;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.socket.DatagramChannelConfig; import io.netty.channel.socket.DatagramChannelConfig;
import io.netty.channel.socket.DefaultDatagramChannelConfig; import io.netty.channel.socket.DefaultDatagramChannelConfig;
@ -98,11 +97,11 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
SET_OPTION = setOption; SET_OPTION = setOption;
} }
private final DatagramChannel channel; private final DatagramChannel javaChannel;
NioDatagramChannelConfig(DatagramChannel channel) { NioDatagramChannelConfig(NioDatagramChannel channel, DatagramChannel javaChannel) {
super(channel.socket()); super(channel, javaChannel.socket());
this.channel = channel; this.javaChannel = javaChannel;
} }
@Override @Override
@ -167,7 +166,7 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} else { } else {
try { try {
return GET_OPTION.invoke(channel, option); return GET_OPTION.invoke(javaChannel, option);
} catch (Exception e) { } catch (Exception e) {
throw new ChannelException(e); throw new ChannelException(e);
} }
@ -179,7 +178,7 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} else { } else {
try { try {
SET_OPTION.invoke(channel, option, value); SET_OPTION.invoke(javaChannel, option, value);
} catch (Exception e) { } catch (Exception e) {
throw new ChannelException(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); super(parent, id, sctpChannel, SelectionKey.OP_READ);
try { try {
sctpChannel.configureBlocking(false); sctpChannel.configureBlocking(false);
config = new DefaultSctpChannelConfig(sctpChannel); config = new DefaultSctpChannelConfig(this, sctpChannel);
notificationHandler = new SctpNotificationHandler(this); notificationHandler = new SctpNotificationHandler(this);
} catch (IOException e) { } catch (IOException e) {
try { try {

View File

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

View File

@ -54,7 +54,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
*/ */
public NioServerSocketChannel() { public NioServerSocketChannel() {
super(null, null, newSocket(), SelectionKey.OP_ACCEPT); super(null, null, newSocket(), SelectionKey.OP_ACCEPT);
config = new DefaultServerSocketChannelConfig(javaChannel().socket()); config = new DefaultServerSocketChannelConfig(this, javaChannel().socket());
} }
@Override @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); throw new ChannelException("Failed to enter non-blocking mode.", e);
} }
config = new DefaultSocketChannelConfig(socket.socket()); config = new DefaultSocketChannelConfig(this, socket.socket());
} }
@Override @Override

View File

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

View File

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

View File

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

View File

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