diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 4e703c60b..e3084c129 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -26,6 +26,7 @@ import java.net.Socket; import java.net.SocketTimeoutException; import java.nio.ByteBuffer; import java.nio.channels.CancelledKeyException; +import java.nio.channels.Channel; import java.nio.channels.FileChannel; import java.nio.channels.NetworkChannel; import java.nio.channels.SelectionKey; @@ -36,7 +37,7 @@ import java.nio.channels.WritableByteChannel; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; + import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -200,10 +201,15 @@ public class NioEndpoint extends AbstractJsseEndpoint @Override public void bind() throws Exception { - serverSock = ServerSocketChannel.open(); + Channel ic = System.inheritedChannel(); + if(ic instanceof ServerSocketChannel) { + serverSock = (ServerSocketChannel) ic; + } else { + serverSock = ServerSocketChannel.open(); + InetSocketAddress addr = (getAddress()!=null?new InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort())); + serverSock.socket().bind(addr,getAcceptCount()); + } socketProperties.setProperties(serverSock.socket()); - InetSocketAddress addr = (getAddress()!=null?new InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort())); - serverSock.socket().bind(addr,getAcceptCount()); serverSock.configureBlocking(true); //mimic APR behavior // Initialize thread count defaults for acceptor, poller