From c016dfa2475922c0866f4e9e7a3575e225f8c7a9 Mon Sep 17 00:00:00 2001 From: fhanik Date: Thu, 22 Jun 2006 22:02:23 +0000 Subject: [PATCH] Dont do the not needed operations, if they are not needed. Performance is just a tad under java.io, which is expected as we need to poll, as opposed to constantly wait for data. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@416481 13f79535-47bb-0310-9956-ffa450edef68 --- .../coyote/http11/InternalNioInputBuffer.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/java/org/apache/coyote/http11/InternalNioInputBuffer.java b/java/org/apache/coyote/http11/InternalNioInputBuffer.java index 2a9575764..44d102fe7 100644 --- a/java/org/apache/coyote/http11/InternalNioInputBuffer.java +++ b/java/org/apache/coyote/http11/InternalNioInputBuffer.java @@ -567,10 +567,14 @@ public class InternalNioInputBuffer implements InputBuffer { try { final SelectionKey key = socket.keyFor(poller.getSelector()); final KeyAttachment att = (KeyAttachment)key.attachment(); - att.setWakeUp(true); - - poller.addEvent( - new Runnable() { + //to do, add in a check, we might have just timed out on the wait, + //so there is no need to register us again. + boolean addToQueue = false; + try { addToQueue = ((key.interestOps()&SelectionKey.OP_READ) != SelectionKey.OP_READ); } catch ( CancelledKeyException ignore ){} + if ( addToQueue ) { + att.setWakeUp(true); + poller.addEvent( + new Runnable() { public void run() { try { if (key != null) key.interestOps(SelectionKey.OP_READ); @@ -582,12 +586,16 @@ public class InternalNioInputBuffer implements InputBuffer { } catch (Exception ignore) {} } } - }); - synchronized (att.getMutex()) { att.getMutex().wait(25);} + }); + }//end if + synchronized (att.getMutex()) { + if ( att.getWakeUp() ) att.getMutex().wait(25); + } }catch ( Exception x ) {} }while ( nRead == 0 && (!timedOut) ); //else throw new IOException(sm.getString("iib.failedread")); - return false; //timeout + //return false; //timeout + throw new IOException("read timed out."); } -- 2.11.0