From: jfclere Date: Thu, 20 May 2010 15:42:17 +0000 (+0000) Subject: Arrange APR logic. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9224806e72dd1e61bf81e3ae450e76d0ed6c2f28;p=tomcat7.0 Arrange APR logic. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@946674 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/coyote/ajp/AjpAprProtocol.java b/java/org/apache/coyote/ajp/AjpAprProtocol.java index 84c68a8cf..b2862795e 100644 --- a/java/org/apache/coyote/ajp/AjpAprProtocol.java +++ b/java/org/apache/coyote/ajp/AjpAprProtocol.java @@ -416,6 +416,11 @@ public class AjpAprProtocol return SocketState.CLOSED; } + // FIXME: Support for this could be added in AJP as well + public SocketState asyncDispatch(long socket, SocketStatus status) { + return SocketState.CLOSED; + } + protected AjpAprProcessor createProcessor() { AjpAprProcessor processor = new AjpAprProcessor(proto.packetSize, proto.endpoint); processor.setAdapter(proto.adapter); diff --git a/java/org/apache/coyote/http11/Http11AprProcessor.java b/java/org/apache/coyote/http11/Http11AprProcessor.java index 54839a59f..14a7c936b 100644 --- a/java/org/apache/coyote/http11/Http11AprProcessor.java +++ b/java/org/apache/coyote/http11/Http11AprProcessor.java @@ -926,7 +926,12 @@ public class Http11AprProcessor implements ActionHook { } /* Copied from the AjpProcessor.java */ - public SocketState asyncDispatch(SocketStatus status) throws IOException { + public SocketState asyncDispatch(long socket, SocketStatus status) throws IOException { + + // Setting up the socket + this.socket = socket; + inputBuffer.setSocket(socket); + outputBuffer.setSocket(socket); RequestInfo rp = request.getRequestProcessor(); try { @@ -1267,11 +1272,7 @@ public class Http11AprProcessor implements ActionHook { RequestInfo rp = request.getRequestProcessor(); if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) { //async handling dispatch.set(true); - try { - asyncDispatch(SocketStatus.STOP); // What to do with return code ? - } catch (IOException ex) { - error = true; - } + endpoint.getHandler().asyncDispatch(this.socket, SocketStatus.STOP); } else { dispatch.set(false); } diff --git a/java/org/apache/coyote/http11/Http11AprProtocol.java b/java/org/apache/coyote/http11/Http11AprProtocol.java index f55fe057e..ae94a0e79 100644 --- a/java/org/apache/coyote/http11/Http11AprProtocol.java +++ b/java/org/apache/coyote/http11/Http11AprProtocol.java @@ -609,6 +609,47 @@ public class Http11AprProtocol implements ProtocolHandler, MBeanRegistration { return SocketState.CLOSED; } + public SocketState asyncDispatch(long socket, SocketStatus status) { + Http11AprProcessor result = connections.get(Long.valueOf(socket)); + + SocketState state = SocketState.CLOSED; + if (result != null) { + // Call the appropriate event + try { + state = result.asyncDispatch(socket, status); + } catch (java.net.SocketException e) { + // SocketExceptions are normal + Http11AprProtocol.log.debug + (sm.getString + ("http11protocol.proto.socketexception.debug"), e); + } catch (java.io.IOException e) { + // IOExceptions are normal + Http11AprProtocol.log.debug + (sm.getString + ("http11protocol.proto.ioexception.debug"), e); + } + // Future developers: if you discover any other + // rare-but-nonfatal exceptions, catch them here, and log as + // above. + catch (Throwable e) { + // any other exception or error is odd. Here we log it + // with "ERROR" level, so it will show up even on + // less-than-verbose logs. + Http11AprProtocol.log.error + (sm.getString("http11protocol.proto.error"), e); + } finally { + if (state != SocketState.LONG) { + connections.remove(Long.valueOf(socket)); + recycledProcessors.offer(result); + if (state == SocketState.OPEN) { + proto.endpoint.getPoller().add(socket); + } + } + } + } + return state; + } + protected Http11AprProcessor createProcessor() { Http11AprProcessor processor = new Http11AprProcessor(proto.maxHttpHeaderSize, proto.endpoint); diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index c67cc76a8..5929e6372 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -38,6 +38,7 @@ import org.apache.tomcat.jni.SSLContext; import org.apache.tomcat.jni.SSLSocket; import org.apache.tomcat.jni.Socket; import org.apache.tomcat.jni.Status; +import org.apache.catalina.core.AprLifecycleListener; /** @@ -368,6 +369,9 @@ public class AprEndpoint extends AbstractEndpoint { if (initialized) return; + if (!AprLifecycleListener.isAprAvailable()) { + throw new Exception(sm.getString("endpoint.init.notavail"); + } // Create the root APR memory pool rootPool = Pool.create(0); @@ -1403,6 +1407,7 @@ public class AprEndpoint extends AbstractEndpoint { public interface Handler extends AbstractEndpoint.Handler { public SocketState process(long socket); public SocketState event(long socket, SocketStatus status); + public SocketState asyncDispatch(long socket, SocketStatus status); } @@ -1458,15 +1463,24 @@ public class AprEndpoint extends AbstractEndpoint { protected class SocketProcessor implements Runnable { protected long socket = 0; + protected boolean async = false; + protected SocketStatus status = SocketStatus.ERROR; public SocketProcessor(long socket) { this.socket = socket; + this.async = false; + } + public SocketProcessor(long socket, boolean asyn, SocketStatus status) { + this.socket = socket; + this.async = asyn; + this.status = status; } public void run() { // Process the request from this socket - if (handler.process(socket) == Handler.SocketState.CLOSED) { + Handler.SocketState state = async?handler.asyncDispatch(socket, status):handler.process(socket); + if (state == Handler.SocketState.CLOSED) { // Close socket and pool Socket.destroy(socket); socket = 0; diff --git a/java/org/apache/tomcat/util/net/res/LocalStrings.properties b/java/org/apache/tomcat/util/net/res/LocalStrings.properties index 4737f9958..686731c78 100644 --- a/java/org/apache/tomcat/util/net/res/LocalStrings.properties +++ b/java/org/apache/tomcat/util/net/res/LocalStrings.properties @@ -30,6 +30,7 @@ endpoint.info.maxThreads=Maximum number of threads ({0}) created for connector w endpoint.init.bind=Socket bind failed: [{0}] {1} endpoint.init.listen=Socket listen failed: [{0}] {1} +endpoint.init.notavail=APR not available endpoint.accept.fail=Socket accept failed endpoint.poll.limitedpollsize=Failed to create poller with specified size of {0} endpoint.poll.initfail=Poller creation failed @@ -37,6 +38,6 @@ endpoint.poll.fail=Critical poller failure (restarting poller): [{0}] {1} endpoint.poll.error=Unexpected poller error endpoint.process.fail=Error allocating socket processor endpoint.sendfile.error=Unexpected sendfile error -endpoint.sendfile.addfail=Sednfile failure: [{0}] {1} +endpoint.sendfile.addfail=Sendfile failure: [{0}] {1} endpoint.sendfile.nosupport=Disabling sendfile, since either the APR version or the system doesn't support it endpoint.warn.noInsecureReneg=Secure renegotation is not supported by the SSL library {0} diff --git a/java/org/apache/tomcat/util/net/res/LocalStrings_es.properties b/java/org/apache/tomcat/util/net/res/LocalStrings_es.properties index 1245809b3..2d4470180 100644 --- a/java/org/apache/tomcat/util/net/res/LocalStrings_es.properties +++ b/java/org/apache/tomcat/util/net/res/LocalStrings_es.properties @@ -27,6 +27,7 @@ endpoint.err.close = Excepci\u00F3n cogida intentando cerrar conector endpoint.noProcessor = No hay procesadores - \u00A1hilo de trabajadir muerto\! endpoint.init.bind = Ligado de conector fall\u00F3\: [{0}] {1} endpoint.init.listen = Escucha de conector fall\u00F3\: [{0}] {1} +endpoint.init.notavail = APR no disponible endpoint.accept.fail = Aceptaci\u00F3n de conector fall\u00F3 endpoint.poll.limitedpollsize = No pude crear encuestador de medida espec\u00EDfica de {0} endpoint.poll.initfail = Fall\u00F3 la creaci\u00F3n del encuestador