@@ -, +, @@ --- --- a/java/org/apache/coyote/http11/Http11NioProtocol.java +++ a/java/org/apache/coyote/http11/Http11NioProtocol.java @@ -70,6 +70,14 @@ return ((NioEndpoint)getEndpoint()).getPollerThreadPriority(); } + public boolean getUseInheritedChannel() { + return ((NioEndpoint)getEndpoint()).getUseInheritedChannel(); + } + + public void setUseInheritedChannel(boolean useInheritedChannel) { + ((NioEndpoint)getEndpoint()).setUseInheritedChannel(useInheritedChannel); + } + // ----------------------------------------------------- JMX related methods --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ a/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -26,6 +26,7 @@ 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.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; @@ -125,6 +126,14 @@ /** + * Use System.inheritableChannel to obtain channel from stdin/stdout + */ + private boolean useInheritedChannel = false; + public void setUseInheritedChannel(boolean useInheritedChannel) { this.useInheritedChannel = useInheritedChannel; } + public boolean getUseInheritedChannel() { return useInheritedChannel; } + + + /** * Priority of the poller threads. */ private int pollerThreadPriority = Thread.NORM_PRIORITY; @@ -200,10 +209,19 @@ @Override public void bind() throws Exception { - serverSock = ServerSocketChannel.open(); + if(getUseInheritedChannel()) { + Channel ic = System.inheritedChannel(); + if(ic instanceof ServerSocketChannel) { + serverSock = (ServerSocketChannel) ic; + } + } + + if(serverSock == null) { + 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 --- a/webapps/docs/config/http.xml +++ a/webapps/docs/config/http.xml @@ -703,6 +703,16 @@

+ +

(boolean)Defines if this connector should inherit an inetd/systemd network socket. + Only one connector can inherit a network socket. This can option can be + used to automatcially start Tomcat once a connection request is made to + the systemd super daemon's port. + The default value is false. See the JavaDoc + for the java.nio.channels.spi.SelectorProvider class for + more details.

+
+

(int)The priority of the poller threads. The default value is 5 (the value of the