diff --git a/pom.xml b/pom.xml index c37d967b08..df556cd38f 100644 --- a/pom.xml +++ b/pom.xml @@ -703,9 +703,11 @@ java.util.zip.Deflater - + java.nio.channels.DatagramChannel java.nio.channels.MembershipKey + java.nio.channels.ServerSocketChannel + java.nio.channels.SocketChannel java.net.StandardProtocolFamily java.nio.channels.spi.SelectorProvider diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java index 6fb114fe0f..019d6a4eeb 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java @@ -188,14 +188,22 @@ public final class NioDatagramChannel @Override protected void doBind(SocketAddress localAddress) throws Exception { - javaChannel().socket().bind(localAddress); + doBind0(localAddress); + } + + private void doBind0(SocketAddress localAddress) throws Exception { + if (PlatformDependent.javaVersion() >= 7) { + javaChannel().bind(localAddress); + } else { + javaChannel().socket().bind(localAddress); + } } @Override protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { if (localAddress != null) { - javaChannel().socket().bind(localAddress); + doBind0(localAddress); } boolean success = false; diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java index eda4b6abb4..9ae2f2ad62 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java @@ -21,6 +21,7 @@ import io.netty.channel.ChannelOutboundBuffer; import io.netty.channel.nio.AbstractNioMessageChannel; import io.netty.channel.socket.DefaultServerSocketChannelConfig; import io.netty.channel.socket.ServerSocketChannelConfig; +import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -122,7 +123,11 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel @Override protected void doBind(SocketAddress localAddress) throws Exception { - javaChannel().socket().bind(localAddress, config.getBacklog()); + if (PlatformDependent.javaVersion() >= 7) { + javaChannel().bind(localAddress, config.getBacklog()); + } else { + javaChannel().socket().bind(localAddress, config.getBacklog()); + } } @Override diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java index 891dd476fa..4868c14439 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java @@ -30,6 +30,7 @@ import io.netty.channel.socket.DefaultSocketChannelConfig; import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.SocketChannelConfig; import io.netty.util.concurrent.GlobalEventExecutor; +import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -240,32 +241,47 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty private void shutdownOutput0(final ChannelPromise promise) { try { - javaChannel().socket().shutdownOutput(); + shutdownOutput0(); promise.setSuccess(); } catch (Throwable t) { promise.setFailure(t); } } + private void shutdownOutput0() throws Exception { + if (PlatformDependent.javaVersion() >= 7) { + javaChannel().shutdownOutput(); + } else { + javaChannel().socket().shutdownOutput(); + } + } + private void shutdownInput0(final ChannelPromise promise) { try { - javaChannel().socket().shutdownInput(); + shutdownInput0(); promise.setSuccess(); } catch (Throwable t) { promise.setFailure(t); } } + private void shutdownInput0() throws Exception { + if (PlatformDependent.javaVersion() >= 7) { + javaChannel().shutdownInput(); + } else { + javaChannel().socket().shutdownInput(); + } + } + private void shutdown0(final ChannelPromise promise) { - Socket socket = javaChannel().socket(); Throwable cause = null; try { - socket.shutdownOutput(); + shutdownOutput0(); } catch (Throwable t) { cause = t; } try { - socket.shutdownInput(); + shutdownInput0(); } catch (Throwable t) { if (cause == null) { promise.setFailure(t); @@ -294,13 +310,21 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty @Override protected void doBind(SocketAddress localAddress) throws Exception { - javaChannel().socket().bind(localAddress); + doBind0(localAddress); + } + + private void doBind0(SocketAddress localAddress) throws Exception { + if (PlatformDependent.javaVersion() >= 7) { + javaChannel().bind(localAddress); + } else { + javaChannel().socket().bind(localAddress); + } } @Override protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { if (localAddress != null) { - javaChannel().socket().bind(localAddress); + doBind0(localAddress); } boolean success = false;