From 4f695994bf760bf5454906cc284b0674ba94f725 Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 17 Sep 2010 14:40:05 +0000 Subject: [PATCH] Code clean-up. Align BIO and NIO to make Async refactoring easier git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@998153 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/coyote/http11/Http11NioProtocol.java | 30 ++++++++++------------ java/org/apache/coyote/http11/Http11Protocol.java | 29 ++++++++------------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java b/java/org/apache/coyote/http11/Http11NioProtocol.java index 2f99de38a..bf1f60e1b 100644 --- a/java/org/apache/coyote/http11/Http11NioProtocol.java +++ b/java/org/apache/coyote/http11/Http11NioProtocol.java @@ -340,10 +340,8 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol { @Override public SocketState process(NioChannel socket) { - Http11NioProcessor processor = null; + Http11NioProcessor processor = connections.remove(socket); try { - processor = connections.remove(socket); - if (processor == null) { processor = recycledProcessors.poll(); } @@ -351,16 +349,17 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol { processor = createProcessor(); } - if (proto.endpoint.isSSLEnabled() && (proto.sslImplementation != null)) { - if (socket instanceof SecureNioChannel) { - SecureNioChannel ch = (SecureNioChannel)socket; - processor.setSslSupport(proto.sslImplementation.getSSLSupport(ch.getSslEngine().getSession())); - }else processor.setSslSupport(null); + if (proto.isSSLEnabled() && + (proto.sslImplementation != null) + && (socket instanceof SecureNioChannel)) { + SecureNioChannel ch = (SecureNioChannel)socket; + processor.setSslSupport( + proto.sslImplementation.getSSLSupport( + ch.getSslEngine().getSession())); } else { processor.setSslSupport(null); } - SocketState state = processor.process(socket); if (state == SocketState.LONG) { // In the middle of processing a request/response. Keep the @@ -389,14 +388,12 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol { } catch (java.net.SocketException e) { // SocketExceptions are normal - Http11NioProtocol.log.debug - (sm.getString - ("http11protocol.proto.socketexception.debug"), e); + log.debug(sm.getString( + "http11protocol.proto.socketexception.debug"), e); } catch (java.io.IOException e) { // IOExceptions are normal - Http11NioProtocol.log.debug - (sm.getString - ("http11protocol.proto.ioexception.debug"), e); + 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 @@ -405,8 +402,7 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol { // 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. - Http11NioProtocol.log.error - (sm.getString("http11protocol.proto.error"), e); + log.error(sm.getString("http11protocol.proto.error"), e); } recycledProcessors.offer(processor); return SocketState.CLOSED; diff --git a/java/org/apache/coyote/http11/Http11Protocol.java b/java/org/apache/coyote/http11/Http11Protocol.java index 7ba195cec..cf2fba3d6 100644 --- a/java/org/apache/coyote/http11/Http11Protocol.java +++ b/java/org/apache/coyote/http11/Http11Protocol.java @@ -237,7 +237,6 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol { @Override public SocketState process(SocketWrapper socket, SocketStatus status) { Http11Processor processor = connections.remove(socket); - boolean recycle = true; try { if (processor == null) { processor = recycledProcessors.poll(); @@ -247,8 +246,9 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol { } if (proto.isSSLEnabled() && (proto.sslImplementation != null)) { - processor.setSSLSupport - (proto.sslImplementation.getSSLSupport(socket.getSocket())); + processor.setSSLSupport( + proto.sslImplementation.getSSLSupport( + socket.getSocket())); } else { processor.setSSLSupport(null); } @@ -257,22 +257,20 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol { if (state == SocketState.LONG) { connections.put(socket, processor); socket.setAsync(true); - recycle = false; } else { connections.remove(socket); socket.setAsync(false); + recycledProcessors.offer(processor); } return state; } catch(java.net.SocketException e) { // SocketExceptions are normal - Http11Protocol.log.debug - (sm.getString - ("http11protocol.proto.socketexception.debug"), e); + log.debug(sm.getString( + "http11protocol.proto.socketexception.debug"), e); } catch (java.io.IOException e) { // IOExceptions are normal - Http11Protocol.log.debug - (sm.getString - ("http11protocol.proto.ioexception.debug"), e); + 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 @@ -281,16 +279,9 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol { // 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. - Http11Protocol.log.error - (sm.getString("http11protocol.proto.error"), e); - } finally { - // if(proto.adapter != null) proto.adapter.recycle(); - // processor.recycle(); - - if (recycle) { - recycledProcessors.offer(processor); - } + log.error(sm.getString("http11protocol.proto.error"), e); } + recycledProcessors.offer(processor); return SocketState.CLOSED; } -- 2.11.0