commit 29c1b51a41db543195253428b5ae3ebd9f826e01 Author: Thomas Meyer Date: Fri Feb 3 19:51:50 2017 +0100 Add systemd/inetd socket activation for Http11NioProtocol. Change-Id: I99214012c7a4421b5975459cb680c4553b859dab diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java b/java/org/apache/coyote/http11/Http11NioProtocol.java index f872ffe07..d6eed7439 100644 --- a/java/org/apache/coyote/http11/Http11NioProtocol.java +++ b/java/org/apache/coyote/http11/Http11NioProtocol.java @@ -70,6 +70,14 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol { return ((NioEndpoint)getEndpoint()).getPollerThreadPriority(); } + public boolean getUseInheritedChannel() { + return ((NioEndpoint)getEndpoint()).getUseInheritedChannel(); + } + + public void setUseInheritedChannel(boolean useInheritedChannel) { + ((NioEndpoint)getEndpoint()).setUseInheritedChannel(useInheritedChannel); + } + // ----------------------------------------------------- JMX related methods diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 334e5811d..7c6f3e319 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; @@ -125,6 +126,14 @@ public class NioEndpoint extends AbstractJsseEndpoint /** + * 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 @@ public class NioEndpoint extends AbstractJsseEndpoint @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 diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml index df4cb51d6..fdafa6af6 100644 --- a/webapps/docs/config/http.xml +++ b/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