From: markt Date: Tue, 16 Aug 2011 15:45:46 +0000 (+0000) Subject: Align keep-alive disable capability across all HTTP processors X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8861306d10467b7699540038c67f67ee14f1e041;p=tomcat7.0 Align keep-alive disable capability across all HTTP processors git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1158331 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/coyote/http11/AbstractHttp11Processor.java b/java/org/apache/coyote/http11/AbstractHttp11Processor.java index bc28feb01..0baadc0dc 100644 --- a/java/org/apache/coyote/http11/AbstractHttp11Processor.java +++ b/java/org/apache/coyote/http11/AbstractHttp11Processor.java @@ -778,6 +778,14 @@ public abstract class AbstractHttp11Processor extends AbstractProcessor { /** + * Processors (currently only HTTP BIO) may elect to disable HTTP keep-alive + * in some circumstances. This method allows the processor implementation to + * determine if keep-alive should be disabled or not. + */ + protected abstract boolean disableKeepAlive(); + + + /** * After reading the request headers, we have to setup the request filters. */ protected void prepareRequest() { diff --git a/java/org/apache/coyote/http11/Http11AprProcessor.java b/java/org/apache/coyote/http11/Http11AprProcessor.java index df0076ded..dd62aa38a 100644 --- a/java/org/apache/coyote/http11/Http11AprProcessor.java +++ b/java/org/apache/coyote/http11/Http11AprProcessor.java @@ -184,6 +184,10 @@ public class Http11AprProcessor extends AbstractHttp11Processor { long soTimeout = endpoint.getSoTimeout(); + if (disableKeepAlive()) { + socketWrapper.setKeepAliveLeft(0); + } + boolean keptAlive = false; boolean openSocket = false; boolean sendfileInProgress = false; @@ -353,6 +357,12 @@ public class Http11AprProcessor extends AbstractHttp11Processor { @Override + protected boolean disableKeepAlive() { + return false; + } + + + @Override protected void resetTimeouts() { // NOOP for APR } diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index c0dd5762d..564e2fba2 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -213,6 +213,10 @@ public class Http11NioProcessor extends AbstractHttp11Processor { long soTimeout = endpoint.getSoTimeout(); + if (disableKeepAlive()) { + socketWrapper.setKeepAliveLeft(0); + } + boolean keptAlive = false; boolean openSocket = false; boolean readComplete = true; @@ -399,6 +403,12 @@ public class Http11NioProcessor extends AbstractHttp11Processor { @Override + protected boolean disableKeepAlive() { + return false; + } + + + @Override public void recycleInternal() { socket = null; cometClose = false; diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java index 48af529c0..25bbea3c2 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -148,17 +148,7 @@ public class Http11Processor extends AbstractHttp11Processor { int soTimeout = endpoint.getSoTimeout(); - int threadRatio = -1; - // These may return zero or negative values - // Only calculate a thread ratio when both are >0 to ensure we get a - // sensible result - if (endpoint.getCurrentThreadsBusy() >0 && - endpoint.getMaxThreads() >0) { - threadRatio = (endpoint.getCurrentThreadsBusy() * 100) - / endpoint.getMaxThreads(); - } - // Disable keep-alive if we are running low on threads - if (threadRatio > getDisableKeepAlivePercentage()) { + if (disableKeepAlive()) { socketWrapper.setKeepAliveLeft(0); } @@ -368,6 +358,26 @@ public class Http11Processor extends AbstractHttp11Processor { @Override + protected boolean disableKeepAlive() { + int threadRatio = -1; + // These may return zero or negative values + // Only calculate a thread ratio when both are >0 to ensure we get a + // sensible result + if (endpoint.getCurrentThreadsBusy() >0 && + endpoint.getMaxThreads() >0) { + threadRatio = (endpoint.getCurrentThreadsBusy() * 100) + / endpoint.getMaxThreads(); + } + // Disable keep-alive if we are running low on threads + if (threadRatio > getDisableKeepAlivePercentage()) { + return true; + } + + return false; + } + + + @Override protected void resetTimeouts() { // NOOP for APR }