From 2941d003f74de5f5070e8c85e79c9f3ba289bf1a Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 8 Jul 2011 16:19:28 +0000 Subject: [PATCH] Yet more protocol alignment (with an eye to aligning with AJP) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1144375 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/coyote/http11/Http11AprProtocol.java | 27 ++++++++------- .../apache/coyote/http11/Http11NioProtocol.java | 38 +++++++++++++--------- java/org/apache/coyote/http11/Http11Protocol.java | 12 +++++-- 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11AprProtocol.java b/java/org/apache/coyote/http11/Http11AprProtocol.java index 27f306aae..b8ae0a84d 100644 --- a/java/org/apache/coyote/http11/Http11AprProtocol.java +++ b/java/org/apache/coyote/http11/Http11AprProtocol.java @@ -265,15 +265,9 @@ public class Http11AprProtocol extends AbstractHttp11Protocol { if (state == SocketState.LONG) { // In the middle of processing a request/response. Keep the - // socket associated with the processor. - connections.put(socket.getSocket(), processor); - - if (processor.isAsync()) { - socket.setAsync(true); - } else if (processor.comet) { - ((AprEndpoint) proto.endpoint).getCometPoller().add( - socket.getSocket().longValue()); - } + // socket associated with the processor. Exact requirements + // depend on type of long poll + longPoll(socket, processor); } else if (state == SocketState.OPEN){ // In keep-alive but between requests. OK to recycle // processor. Continue to poll for the next request. @@ -300,8 +294,7 @@ public class Http11AprProtocol extends AbstractHttp11Protocol { // 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); + log.error(sm.getString("http11protocol.proto.error"), e); } release(socket, processor, true, false); return SocketState.CLOSED; @@ -313,6 +306,18 @@ public class Http11AprProtocol extends AbstractHttp11Protocol { // NOOP for APR } + private void longPoll(SocketWrapper socket, + Http11AprProcessor processor) { + connections.put(socket.getSocket(), processor); + + if (processor.isAsync()) { + socket.setAsync(true); + } else if (processor.comet) { + ((AprEndpoint) proto.endpoint).getCometPoller().add( + socket.getSocket().longValue()); + } + } + protected Http11AprProcessor createProcessor() { Http11AprProcessor processor = new Http11AprProcessor( proto.getMaxHttpHeaderSize(), (AprEndpoint)proto.endpoint, diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java b/java/org/apache/coyote/http11/Http11NioProtocol.java index b02d16b93..0711d7222 100644 --- a/java/org/apache/coyote/http11/Http11NioProtocol.java +++ b/java/org/apache/coyote/http11/Http11NioProtocol.java @@ -280,22 +280,9 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol { if (state == SocketState.LONG) { // In the middle of processing a request/response. Keep the - // socket associated with the processor. - connections.put(socket, processor); - - if (processor.isAsync()) { - socket.setAsync(true); - } else { - // Either: - // - this is comet request - // - the request line/headers have not been completely - // read - SelectionKey key = socket.getSocket().getIOChannel().keyFor( - socket.getSocket().getPoller().getSelector()); - key.interestOps(SelectionKey.OP_READ); - ((KeyAttachment) socket).interestOps( - SelectionKey.OP_READ); - } + // socket associated with the processor. Exact requirements + // depend on type of long poll + longPoll(socket, processor); } else if (state == SocketState.OPEN){ // In keep-alive but between requests. OK to recycle // processor. Continue to poll for the next request. @@ -343,6 +330,25 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol { } + private void longPoll(SocketWrapper socket, + Http11NioProcessor processor) { + connections.put(socket, processor); + + if (processor.isAsync()) { + socket.setAsync(true); + } else { + // Either: + // - this is comet request + // - the request line/headers have not been completely + // read + SelectionKey key = socket.getSocket().getIOChannel().keyFor( + socket.getSocket().getPoller().getSelector()); + key.interestOps(SelectionKey.OP_READ); + ((KeyAttachment) socket).interestOps( + SelectionKey.OP_READ); + } + } + public Http11NioProcessor createProcessor() { Http11NioProcessor processor = new Http11NioProcessor( proto.getMaxHttpHeaderSize(), (NioEndpoint)proto.endpoint, diff --git a/java/org/apache/coyote/http11/Http11Protocol.java b/java/org/apache/coyote/http11/Http11Protocol.java index 4ab1eeb98..5d188e332 100644 --- a/java/org/apache/coyote/http11/Http11Protocol.java +++ b/java/org/apache/coyote/http11/Http11Protocol.java @@ -166,7 +166,7 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol { processor = createProcessor(); } - initSsl(socket,processor); + initSsl(socket, processor); SocketState state = SocketState.CLOSED; do { @@ -185,8 +185,9 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol { if (state == SocketState.LONG) { // In the middle of processing a request/response. Keep the - // socket associated with the processor. - connections.put(socket, processor); + // socket associated with the processor. Exact requirements + // depend on type of long poll + longPoll(socket, processor); } else if (state == SocketState.OPEN){ // In keep-alive but between requests. OK to recycle // processor. Continue to poll for the next request. @@ -231,6 +232,11 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol { } + private void longPoll(SocketWrapper socket, + Http11Processor processor) { + connections.put(socket, processor); + } + protected Http11Processor createProcessor() { Http11Processor processor = new Http11Processor( proto.getMaxHttpHeaderSize(), (JIoEndpoint)proto.endpoint, -- 2.11.0