You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2018/06/29 15:42:53 UTC
svn commit: r1834689 - in /tomcat/trunk:
java/org/apache/tomcat/util/net/LocalStrings.properties
java/org/apache/tomcat/util/net/NioEndpoint.java webapps/docs/changelog.xml
webapps/docs/config/http.xml
Author: remm
Date: Fri Jun 29 15:42:53 2018
New Revision: 1834689
URL: http://svn.apache.org/viewvc?rev=1834689&view=rev
Log:
60560: Add support for using an inherited channel to the NIO connector. Based on a patch submitted by Thomas Meyer with testing and suggestions by Coty Sutherland.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/LocalStrings.properties
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
tomcat/trunk/webapps/docs/changelog.xml
tomcat/trunk/webapps/docs/config/http.xml
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/LocalStrings.properties?rev=1834689&r1=1834688&r2=1834689&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/LocalStrings.properties Fri Jun 29 15:42:53 2018
@@ -47,6 +47,7 @@ endpoint.duplicateSslHostName=Multiple S
endpoint.executor.fail=Executor rejected socket [{0}] for processing
endpoint.getAttribute=[{0}] is [{1}]
endpoint.init.bind=Socket bind failed: [{0}] [{1}]
+endpoint.init.bind.inherited=No inherited channel while the connector was configured to use one
endpoint.init.listen=Socket listen failed: [{0}] [{1}]
endpoint.init.notavail=APR not available
endpoint.invalidJmxNameSslHost=Unable to generate a valid JMX object name for the SSLHostConfig associated with host [{0}]
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1834689&r1=1834688&r2=1834689&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri Jun 29 15:42:53 2018
@@ -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;
@@ -125,6 +126,13 @@ public class NioEndpoint extends Abstrac
/**
+ * 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;
@@ -221,10 +229,21 @@ public class NioEndpoint extends Abstrac
// Separated out to make it easier for folks that extend NioEndpoint to
// implement custom [server]sockets
protected void initServerSocket() throws Exception {
- serverSock = ServerSocketChannel.open();
- socketProperties.setProperties(serverSock.socket());
- InetSocketAddress addr = (getAddress()!=null?new InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort()));
- serverSock.socket().bind(addr,getAcceptCount());
+ if (!getUseInheritedChannel()) {
+ serverSock = ServerSocketChannel.open();
+ socketProperties.setProperties(serverSock.socket());
+ InetSocketAddress addr = (getAddress()!=null?new InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort()));
+ serverSock.socket().bind(addr,getAcceptCount());
+ } else {
+ // Retrieve the channel provided by the OS
+ Channel ic = System.inheritedChannel();
+ if (ic instanceof ServerSocketChannel) {
+ serverSock = (ServerSocketChannel) ic;
+ }
+ if (serverSock == null) {
+ throw new IllegalArgumentException(sm.getString("endpoint.init.bind.inherited"));
+ }
+ }
serverSock.configureBlocking(true); //mimic APR behavior
}
@@ -309,9 +328,11 @@ public class NioEndpoint extends Abstrac
if (running) {
stop();
}
- // Close server socket
- serverSock.socket().close();
- serverSock.close();
+ if (!getUseInheritedChannel()) {
+ // Close server socket
+ serverSock.socket().close();
+ serverSock.close();
+ }
serverSock = null;
destroySsl();
super.unbind();
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1834689&r1=1834688&r2=1834689&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Jun 29 15:42:53 2018
@@ -74,6 +74,11 @@
<bug>56676</bug>: Add a default location for the native library, as
${catalina.home}/bin, which the testsuite already uses. (remm)
</fix>
+ <update>
+ <bug>60560</bug>: Add support for using an inherited channel to
+ the NIO connector. Based on a patch submitted by Thomas Meyer with
+ testing and suggestions by Coty Sutherland. (remm)
+ </update>
</changelog>
</subsection>
<subsection name="Other">
Modified: tomcat/trunk/webapps/docs/config/http.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/http.xml?rev=1834689&r1=1834688&r2=1834689&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/http.xml (original)
+++ tomcat/trunk/webapps/docs/config/http.xml Fri Jun 29 15:42:53 2018
@@ -870,6 +870,16 @@
value is set to false. Default value is <code>-1</code> (unlimited).</p>
</attribute>
+ <attribute name="useInheritedChannel" required="false">
+ <p>(bool)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 <code>false</code>. See the JavaDoc
+ for the <code>java.nio.channels.spi.SelectorProvider</code> class for
+ more details.</p>
+ </attribute>
+
<attribute name="command-line-options" required="false">
<p>The following command line options are available for the NIO
connector:<br/>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org