Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5AC50965C for ; Sun, 15 Jan 2012 20:04:33 +0000 (UTC) Received: (qmail 4771 invoked by uid 500); 15 Jan 2012 20:04:32 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 4722 invoked by uid 500); 15 Jan 2012 20:04:31 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 4713 invoked by uid 99); 15 Jan 2012 20:04:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Jan 2012 20:04:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FRT_STOCK2 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Jan 2012 20:04:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2F133238889B for ; Sun, 15 Jan 2012 20:04:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1231740 - in /tomcat/trunk/java/org/apache/tomcat/util/net: AprEndpoint.java JIoEndpoint.java NioEndpoint.java Date: Sun, 15 Jan 2012 20:04:06 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120115200406.2F133238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: markt Date: Sun Jan 15 20:04:05 2012 New Revision: 1231740 URL: http://svn.apache.org/viewvc?rev=1231740&view=rev Log: Ensure that connections from unlockAccept() do not get passed to a processor. Reduce differences between BIO, NIO and APR acceptor code. Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1231740&r1=1231739&r2=1231740&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Sun Jan 15 20:04:05 2012 @@ -941,21 +941,16 @@ public class AprEndpoint extends Abstrac return log; } - // --------------------------------------------------- Acceptor Inner Class - + // --------------------------------------------------- Acceptor Inner Class /** - * Server socket acceptor thread. + * The background thread that listens for incoming TCP/IP connections and + * hands them off to an appropriate processor. */ protected class Acceptor extends AbstractEndpoint.Acceptor { private final Log log = LogFactory.getLog(AprEndpoint.Acceptor.class); - - /** - * The background thread that listens for incoming TCP/IP connections and - * hands them off to an appropriate processor. - */ @Override public void run() { @@ -997,17 +992,13 @@ public class AprEndpoint extends Abstrac // Successful accept, reset the error delay errorDelay = 0; - /* - * In the case of a deferred accept unlockAccept needs to - * send data. This data will be rubbish, so destroy the - * socket and don't process it. - */ - if (deferAccept && (paused || !running)) { - destroySocket(socket); - continue; - } - // Hand this socket off to an appropriate processor - if (!processSocketWithOptions(socket)) { + if (running && !paused) { + // Hand this socket off to an appropriate processor + if (!processSocketWithOptions(socket)) { + // Close socket and pool right away + destroySocket(socket); + } + } else { // Close socket and pool right away destroySocket(socket); } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=1231740&r1=1231739&r2=1231740&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Sun Jan 15 20:04:05 2012 @@ -177,14 +177,11 @@ public class JIoEndpoint extends Abstrac // --------------------------------------------------- Acceptor Inner Class /** - * Server socket acceptor thread. + * The background thread that listens for incoming TCP/IP connections and + * hands them off to an appropriate processor. */ protected class Acceptor extends AbstractEndpoint.Acceptor { - /** - * The background thread that listens for incoming TCP/IP connections and - * hands them off to an appropriate processor. - */ @Override public void run() { @@ -227,23 +224,15 @@ public class JIoEndpoint extends Abstrac errorDelay = 0; // Configure the socket - if (setSocketOptions(socket)) { + if (running && !paused && setSocketOptions(socket)) { // Hand this socket off to an appropriate processor if (!processSocket(socket)) { // Close socket right away - try { - socket.close(); - } catch (IOException e) { - // Ignore - } + closeSocket(socket); } } else { // Close socket right away - try { - socket.close(); - } catch (IOException e) { - // Ignore - } + closeSocket(socket); } } catch (IOException x) { if (running) { @@ -257,13 +246,21 @@ public class JIoEndpoint extends Abstrac ExceptionUtils.handleThrowable(t); log.error(sm.getString("endpoint.accept.fail"), t); } - // The processor will recycle itself when it finishes } state = AcceptorState.ENDED; } } + private void closeSocket(Socket socket) { + try { + socket.close(); + } catch (IOException e) { + // Ignore + } + } + + // ------------------------------------------- SocketProcessor Inner Class Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1231740&r1=1231739&r2=1231740&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Sun Jan 15 20:04:05 2012 @@ -742,17 +742,14 @@ public class NioEndpoint extends Abstrac return log; } - // --------------------------------------------------- Acceptor Inner Class - + // --------------------------------------------------- Acceptor Inner Class /** - * Server socket acceptor thread. + * The background thread that listens for incoming TCP/IP connections and + * hands them off to an appropriate processor. */ protected class Acceptor extends AbstractEndpoint.Acceptor { - /** - * The background thread that listens for incoming TCP/IP connections and - * hands them off to an appropriate processor. - */ + @Override public void run() { @@ -794,24 +791,17 @@ public class NioEndpoint extends Abstrac // Successful accept, reset the error delay errorDelay = 0; - // Hand this socket off to an appropriate processor - //TODO FIXME - this is currently a blocking call, meaning we will be blocking - //further accepts until there is a thread available. - if ( running && (!paused) && socket != null ) { - // setSocketOptions() will add channel to the poller - // if successful + // setSocketOptions() will add channel to the poller + // if successful + if (running && !paused) { if (!setSocketOptions(socket)) { - try { - socket.socket().close(); - socket.close(); - } catch (IOException ix) { - if (log.isDebugEnabled()) - log.debug("", ix); - } + closeSocket(socket); } + } else { + closeSocket(socket); } } catch (SocketTimeoutException sx) { - //normal condition + // Ignore: Normal condition } catch (IOException x) { if (running) { log.error(sm.getString("endpoint.accept.fail"), x); @@ -837,9 +827,27 @@ public class NioEndpoint extends Abstrac ExceptionUtils.handleThrowable(t); log.error(sm.getString("endpoint.accept.fail"), t); } - }//while + } state = AcceptorState.ENDED; - }//run + } + } + + + private void closeSocket(SocketChannel socket) { + try { + socket.socket().close(); + } catch (IOException ioe) { + if (log.isDebugEnabled()) { + log.debug("", ioe); + } + } + try { + socket.close(); + } catch (IOException ioe) { + if (log.isDebugEnabled()) { + log.debug("", ioe); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org