From: mturk
Date: Wed, 29 Nov 2006 12:26:37 +0000 (+0000)
Subject: Commit the voted keepAliveTimeout patch.
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0147be3206fa3d1d61b1a8b97368f2d587a97c57;p=tomcat7.0
Commit the voted keepAliveTimeout patch.
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@480552 13f79535-47bb-0310-9956-ffa450edef68
---
diff --git a/java/org/apache/coyote/ajp/AjpAprProtocol.java b/java/org/apache/coyote/ajp/AjpAprProtocol.java
index 75e7d4b53..df040652e 100644
--- a/java/org/apache/coyote/ajp/AjpAprProtocol.java
+++ b/java/org/apache/coyote/ajp/AjpAprProtocol.java
@@ -433,7 +433,17 @@ public class AjpAprProtocol
packetSize = i;
}
-
+ public int getKeepAliveTimeout() {
+ return ep.getKeepAliveTimeout();
+ }
+
+
+ public void setKeepAliveTimeout( int i ) {
+ ep.setKeepAliveTimeout(i);
+ setAttribute("keepAliveTimeout", "" + i);
+ }
+
+
// -------------------------------------- AjpConnectionHandler Inner Class
diff --git a/java/org/apache/coyote/ajp/Constants.java b/java/org/apache/coyote/ajp/Constants.java
index 99f2e38bb..68ec5aa7b 100644
--- a/java/org/apache/coyote/ajp/Constants.java
+++ b/java/org/apache/coyote/ajp/Constants.java
@@ -42,6 +42,7 @@ public final class Constants {
public static final int DEFAULT_CONNECTION_LINGER = -1;
public static final int DEFAULT_CONNECTION_TIMEOUT = -1;
public static final int DEFAULT_CONNECTION_UPLOAD_TIMEOUT = 300000;
+ public static final int DEFAULT_KEEPALIVE_TIMEOUT = 15000;
public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0;
public static final boolean DEFAULT_TCP_NO_DELAY = true;
diff --git a/java/org/apache/coyote/http11/Constants.java b/java/org/apache/coyote/http11/Constants.java
index ff07a60d1..5fafe94e2 100644
--- a/java/org/apache/coyote/http11/Constants.java
+++ b/java/org/apache/coyote/http11/Constants.java
@@ -39,6 +39,7 @@ public final class Constants {
public static final int DEFAULT_CONNECTION_LINGER = -1;
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
public static final int DEFAULT_CONNECTION_UPLOAD_TIMEOUT = 300000;
+ public static final int DEFAULT_KEEPALIVE_TIMEOUT = 15000;
public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0;
public static final boolean DEFAULT_TCP_NO_DELAY = true;
diff --git a/java/org/apache/coyote/http11/Http11AprProcessor.java b/java/org/apache/coyote/http11/Http11AprProcessor.java
index 1227718f3..ef2371b1c 100644
--- a/java/org/apache/coyote/http11/Http11AprProcessor.java
+++ b/java/org/apache/coyote/http11/Http11AprProcessor.java
@@ -209,6 +209,12 @@ public class Http11AprProcessor implements ActionHook {
*/
protected int maxKeepAliveRequests = -1;
+ /**
+ * The number of seconds Tomcat will wait for a subsequent request
+ * before closing the connection.
+ */
+ protected int keepAliveTimeout = 15000;
+
/**
* SSL enabled ?
@@ -704,6 +710,19 @@ public class Http11AprProcessor implements ActionHook {
return timeout;
}
+ /**
+ * Set the Keep-Alive timeout.
+ */
+ public void setKeepAliveTimeout(int timeout) {
+ keepAliveTimeout = timeout;
+ }
+
+ /**
+ * Return the number Keep-Alive timeout.
+ */
+ public int getKeepAliveTimeout() {
+ return keepAliveTimeout;
+ }
/**
* Set the server header name.
diff --git a/java/org/apache/coyote/http11/Http11AprProtocol.java b/java/org/apache/coyote/http11/Http11AprProtocol.java
index bcfefce29..1df4c8217 100644
--- a/java/org/apache/coyote/http11/Http11AprProtocol.java
+++ b/java/org/apache/coyote/http11/Http11AprProtocol.java
@@ -202,6 +202,7 @@ public class Http11AprProtocol implements ProtocolHandler, MBeanRegistration
private int socketBuffer = 9000;
private Adapter adapter;
private Http11ConnectionHandler cHandler;
+ private int keepAliveTimeout = 15000; // 15 seconds as in Apache HTTPD server
/**
* Compression value.
@@ -463,11 +464,20 @@ public class Http11AprProtocol implements ProtocolHandler, MBeanRegistration
setAttribute("maxKeepAliveRequests", "" + mkar);
}
+
/**
- * Return the Keep-Alive policy for the connection.
+ * The number of seconds Tomcat will wait for a subsequent request
+ * before closing the connection. The default is the same as for
+ * Apache HTTP Server (15 000 milliseconds).
*/
- public boolean getKeepAlive() {
- return ((maxKeepAliveRequests != 0) && (maxKeepAliveRequests != 1));
+ public int getKeepAliveTimeout()
+ {
+ return keepAliveTimeout;
+ }
+
+ public void setKeepAliveTimeout(int timeout)
+ {
+ keepAliveTimeout = timeout;
}
/**
diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java
index 22ca60dda..fb27ae537 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -186,6 +186,12 @@ public class Http11Processor implements ActionHook {
*/
protected int maxKeepAliveRequests = -1;
+ /**
+ * The number of seconds Tomcat will wait for a subsequent request
+ * before closing the connection.
+ */
+ protected int keepAliveTimeout = 15000;
+
/**
* SSL information.
@@ -621,6 +627,21 @@ public class Http11Processor implements ActionHook {
return maxKeepAliveRequests;
}
+ /**
+ * Set the Keep-Alive timeout.
+ */
+ public void setKeepAliveTimeout(int timeout) {
+ keepAliveTimeout = timeout;
+ }
+
+
+ /**
+ * Return the number Keep-Alive timeout.
+ */
+ public int getKeepAliveTimeout() {
+ return keepAliveTimeout;
+ }
+
/**
* Set the maximum size of a POST which will be buffered in SSL mode.
@@ -773,8 +794,13 @@ public class Http11Processor implements ActionHook {
// Parsing the request header
try {
- if( !disableUploadTimeout && keptAlive && soTimeout > 0 ) {
- socket.setSoTimeout(soTimeout);
+ if (!disableUploadTimeout && keptAlive) {
+ if (keepAliveTimeout > 0) {
+ socket.setSoTimeout(keepAliveTimeout);
+ }
+ else if (soTimeout > 0) {
+ socket.setSoTimeout(soTimeout);
+ }
}
inputBuffer.parseRequestLine();
request.setStartTime(System.currentTimeMillis());
diff --git a/java/org/apache/coyote/http11/Http11Protocol.java b/java/org/apache/coyote/http11/Http11Protocol.java
index a9dcaa5d9..881d332f9 100644
--- a/java/org/apache/coyote/http11/Http11Protocol.java
+++ b/java/org/apache/coyote/http11/Http11Protocol.java
@@ -71,6 +71,7 @@ public class Http11Protocol
public Http11Protocol() {
setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
+ setKeepAliveTimeout(Constants.DEFAULT_KEEPALIVE_TIMEOUT);
//setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
}
@@ -285,6 +286,22 @@ public class Http11Protocol
public int getMaxKeepAliveRequests() { return maxKeepAliveRequests; }
public void setMaxKeepAliveRequests(int mkar) { maxKeepAliveRequests = mkar; }
+ // HTTP
+ /**
+ * The number of seconds Tomcat will wait for a subsequent request
+ * before closing the connection. The default is the same as for
+ * Apache HTTP Server (15 000 milliseconds).
+ */
+ protected int keepAliveTimeout = 15000;
+ public int getKeepAliveTimeout()
+ {
+ return keepAliveTimeout;
+ }
+
+ public void setKeepAliveTimeout(int timeout)
+ {
+ keepAliveTimeout = timeout;
+ }
// HTTP
/**
@@ -584,6 +601,7 @@ public class Http11Protocol
new Http11Processor(protocol.maxHttpHeaderSize, protocol.endpoint);
processor.setAdapter(protocol.adapter);
processor.setMaxKeepAliveRequests(protocol.maxKeepAliveRequests);
+ processor.setKeepAliveTimeout(protocol.keepAliveTimeout);
processor.setTimeout(protocol.timeout);
processor.setDisableUploadTimeout(protocol.disableUploadTimeout);
processor.setCompression(protocol.compression);
diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java
index 07fbf42e2..5320daab5 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -258,6 +258,21 @@ public class AprEndpoint {
/**
+ * Keep-Alive timeout.
+ */
+ protected int keepAliveTimeout = 15000;
+ public int getKeepAliveTimeout()
+ {
+ return keepAliveTimeout;
+ }
+
+ public void setKeepAliveTimeout(int timeout)
+ {
+ keepAliveTimeout = timeout;
+ }
+
+
+ /**
* Timeout on first request read before going to the poller, in ms.
*/
protected int firstReadTimeout = -1;
@@ -1143,11 +1158,11 @@ public class AprEndpoint {
protected void init() {
pool = Pool.create(serverSockPool);
int size = pollerSize / pollerThreadCount;
- int timeout = soTimeout;
+ int timeout = keepAliveTimeout;
if (comet) {
// FIXME: Find an appropriate timeout value, for now, "longer than usual"
// semms appropriate
- timeout = soTimeout * 50;
+ timeout = keepAliveTimeout * 50;
}
serverPollset = allocatePoller(size, pool, timeout);
if (serverPollset == 0 && size > 1024) {
@@ -1561,14 +1576,14 @@ public class AprEndpoint {
protected void init() {
pool = Pool.create(serverSockPool);
int size = sendfileSize / sendfileThreadCount;
- sendfilePollset = allocatePoller(size, pool, soTimeout);
+ sendfilePollset = allocatePoller(size, pool, keepAliveTimeout);
if (sendfilePollset == 0 && size > 1024) {
size = 1024;
- sendfilePollset = allocatePoller(size, pool, soTimeout);
+ sendfilePollset = allocatePoller(size, pool, keepAliveTimeout);
}
if (sendfilePollset == 0) {
size = 62;
- sendfilePollset = allocatePoller(size, pool, soTimeout);
+ sendfilePollset = allocatePoller(size, pool, keepAliveTimeout);
}
desc = new long[size * 2];
sendfileData = new HashMap(size);
diff --git a/webapps/docs/config/ajp.xml b/webapps/docs/config/ajp.xml
index d61c49b7d..505863d2d 100644
--- a/webapps/docs/config/ajp.xml
+++ b/webapps/docs/config/ajp.xml
@@ -218,6 +218,12 @@ with AJP enabled
presented. The default value is infinite (i.e. no timeout).
+
+ The number of milliseconds this Connector will wait,
+ subsequent request before closing the connection.
+ The default value is infinite (i.e. no timeout).
+
+
deprecated
The minimum number of processors to start at initialization time.
diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml
index ddbcaa08a..619662409 100644
--- a/webapps/docs/config/http.xml
+++ b/webapps/docs/config/http.xml
@@ -270,6 +270,12 @@
presented. The default value is 60000 (i.e. 60 seconds).
+
+ The number of milliseconds this Connector will wait,
+ subsequent request before closing the connection.
+ The default value is 15000 (i.e. 15 seconds).
+
+
This flag allows the servlet container to use a different, longer
connection timeout while a servlet is being executed, which in the end