From 22b0098be729bd65ceb8fb0a2ec3872dc739072d Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 2 May 2013 12:57:48 +1000 Subject: [PATCH] 406617 Spin in Request.recylce removed loop from read, so only a single attempt a blocking for content. --- .../eclipse/jetty/server/HttpConnection.java | 1 + .../org/eclipse/jetty/server/HttpInput.java | 55 +++++++++++++------ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index f7e675eea7c..88c53c7d719 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -561,6 +561,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http if (getEndPoint().isInputShutdown()) { _parser.shutdownInput(); + shutdown(); return; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java index d5db8371dcc..8f19b56bd46 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java @@ -96,32 +96,53 @@ public abstract class HttpInput extends ServletInputStream T item = null; synchronized (lock()) { - while (item == null) + // Get the current head of the input Q + item = _inputQ.peekUnsafe(); + + // Skip empty items at the head of the queue + while (item != null && remaining(item) == 0) { + _inputQ.pollUnsafe(); + onContentConsumed(item); + LOG.debug("{} consumed {}", this, item); item = _inputQ.peekUnsafe(); - while (item != null && remaining(item) == 0) + + // If that was the last item then notify + if (item==null) + onAllContentConsumed(); + } + + // If we have no item + if (item == null) + { + // Was it unexpectedly EOF'd? + if (isEarlyEOF()) + throw new EofException(); + + // check for EOF + if (isShutdown()) { - _inputQ.pollUnsafe(); - onContentConsumed(item); - LOG.debug("{} consumed {}", this, item); - item = _inputQ.peekUnsafe(); + onEOF(); + return -1; } - if (item == null) + // OK then block for some more content + blockForContent(); + + // If still not content, we must be closed + item = _inputQ.peekUnsafe(); + if (item==null) { - onAllContentConsumed(); - if (isEarlyEOF()) throw new EofException(); + + // blockForContent will only return with no + // content if it is closed. + if (!isShutdown()) + LOG.warn("unexpected !EOF state"); - // check for EOF - if (isShutdown()) - { - onEOF(); - return -1; - } - - blockForContent(); + onEOF(); + return -1; } } }