Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 84944 invoked from network); 22 Jun 2006 19:09:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Jun 2006 19:09:43 -0000 Received: (qmail 63492 invoked by uid 500); 22 Jun 2006 19:07:29 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 62411 invoked by uid 500); 22 Jun 2006 19:07:22 -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 60193 invoked by uid 500); 22 Jun 2006 19:07:10 -0000 Delivered-To: apmail-jakarta-tomcat-dev@jakarta.apache.org Received: (qmail 56781 invoked by uid 99); 22 Jun 2006 19:05:25 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jun 2006 12:05:25 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jun 2006 12:05:24 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 608491A983A; Thu, 22 Jun 2006 12:05:04 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r416444 [1/2] - in /tomcat/tc6.0.x/trunk/java/org/apache: coyote/http11/Http11NioProcessor.java coyote/http11/InternalNioInputBuffer.java tomcat/util/net/NioEndpoint.java Date: Thu, 22 Jun 2006 19:05:03 -0000 To: tomcat-dev@jakarta.apache.org From: fhanik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060622190504.608491A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: fhanik Date: Thu Jun 22 12:05:02 2006 New Revision: 416444 URL: http://svn.apache.org/viewvc?rev=416444&view=rev Log: Fix so that we don't do a busy read, instead we are properly doing a NIO poller wait This way, we can achieve blocking read, without wasting CPU cycles. Since we are using Java 5, I will be changing this implementation from using synchronized to using the Exchanger, this is also to avoid anyi locks that can happen. For example, in the current implementation the poller can call notify before we have had a chance to call wait Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=416444&r1=416443&r2=416444&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Thu Jun 22 12:05:02 2006 @@ -90,8 +90,8 @@ readTimeout = timeout; //readTimeout = -1; } - inputBuffer = new InternalNioInputBuffer(request, headerBufferSize, - readTimeout); + inputBuffer = new InternalNioInputBuffer(request, headerBufferSize,readTimeout); + inputBuffer.setPoller(endpoint.getPoller()); request.setInputBuffer(inputBuffer); response = new Response(); Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=416444&r1=416443&r2=416444&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Thu Jun 22 12:05:02 2006 @@ -28,6 +28,10 @@ import org.apache.tomcat.util.buf.MessageBytes; import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.res.StringManager; +import java.nio.channels.Selector; +import java.nio.channels.SelectionKey; +import org.apache.tomcat.util.net.NioEndpoint.KeyAttachment; +import org.apache.tomcat.util.net.NioEndpoint.Poller; /** * Implementation of InputBuffer which provides HTTP request header parsing as @@ -183,7 +187,7 @@ * header. */ protected long readTimeout; - + private Poller poller; // ------------------------------------------------------------- Properties @@ -203,6 +207,9 @@ return socket; } + public Poller getPoller() { + return poller; + } /** * Add an input filter to the filter library. @@ -272,6 +279,9 @@ this.swallowInput = swallowInput; } + public void setPoller(Poller poller) { + this.poller = poller; + } // --------------------------------------------------------- Public Methods @@ -551,7 +561,20 @@ return false; } timedOut = (readTimeout != -1) && ((System.currentTimeMillis()-start)>this.readTimeout); - //if ( !timedOut && nRead == 0 ) try {Thread.sleep(5);}catch ( Exception x ) {} + if ( !timedOut && nRead == 0 ) + try { + final SelectionKey key = socket.keyFor(poller.getSelector()); + KeyAttachment att = (KeyAttachment)key.attachment(); + att.setWakeUp(true); + + poller.addEvent( + new Runnable() { + public void run() { + if ( key != null ) key.interestOps(SelectionKey.OP_READ); + } + }); + synchronized (att.getMutex()) { att.getMutex().wait(25);} + }catch ( Exception x ) {} }while ( nRead == 0 && (!timedOut) ); //else throw new IOException(sm.getString("iib.failedread")); return false; //timeout --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org