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 09d254cb559..44ed04fb5e2 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 @@ -28,7 +28,6 @@ import javax.servlet.ServletInputStream; import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.RuntimeIOException; -import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.ArrayQueue; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; @@ -115,7 +114,6 @@ public class HttpInput extends ServletInputStream implements Runnable private void wake() { - // TODO review if this is correct _channelState.getHttpChannel().getConnector().getExecutor().execute(_channelState.getHttpChannel()); } @@ -349,7 +347,7 @@ public class HttpInput extends ServletInputStream implements Runnable throw (IOException)new InterruptedIOException().initCause(e); } } - + /** * Adds some content to this input stream. * @@ -360,18 +358,14 @@ public class HttpInput extends ServletInputStream implements Runnable boolean woken=false; synchronized (_inputQ) { - boolean wasEmpty = _inputQ.isEmpty(); - _inputQ.add(item); + _inputQ.addUnsafe(item); if (LOG.isDebugEnabled()) LOG.debug("{} addContent {}", this, item); - if (wasEmpty) // TODO do we need this guard? - { - if (_listener==null) - _inputQ.notify(); - else - woken=_channelState.onReadPossible(); - } + if (_listener==null) + _inputQ.notify(); + else + woken=_channelState.onReadPossible(); } return woken; @@ -381,7 +375,7 @@ public class HttpInput extends ServletInputStream implements Runnable { synchronized (_inputQ) { - return !_inputQ.isEmpty(); + return _inputQ.sizeUnsafe()>0; } } @@ -580,7 +574,7 @@ public class HttpInput extends ServletInputStream implements Runnable { if (error!=null) { - _channelState.getHttpChannel().getResponse().getHttpFields().add(HttpConnection.CONNECTION_CLOSE); // TODO ??? + _channelState.getHttpChannel().getResponse().getHttpFields().add(HttpConnection.CONNECTION_CLOSE); listener.onError(error); } else if (aeof) @@ -596,7 +590,7 @@ public class HttpInput extends ServletInputStream implements Runnable { if (aeof || error==null) { - _channelState.getHttpChannel().getResponse().getHttpFields().add(HttpConnection.CONNECTION_CLOSE); // TODO ??? + _channelState.getHttpChannel().getResponse().getHttpFields().add(HttpConnection.CONNECTION_CLOSE); listener.onError(e); } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayQueue.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayQueue.java index 0c3b5452615..a02c804ace6 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayQueue.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayQueue.java @@ -254,6 +254,12 @@ public class ArrayQueue extends AbstractList implements Queue } } + /* ------------------------------------------------------------ */ + public int sizeUnsafe() + { + return _size; + } + /* ------------------------------------------------------------ */ @Override public E get(int index)