398467 Servlet 3.1 Non Blocking IO

fixed lock issue detected by Threadsafe from contemplateltd.com
This commit is contained in:
Greg Wilkins 2013-07-15 15:24:14 +10:00
parent 987aa846cc
commit 9f5f7e9ead
3 changed files with 22 additions and 70 deletions

View File

@ -217,7 +217,28 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl
}
}
public abstract void consumeAll();
/* ------------------------------------------------------------ */
public void consumeAll()
{
synchronized (lock())
{
try
{
while (!isFinished())
{
T item = getNextContent();
if (item==null)
_state.waitForContent(this);
else
consume(item,remaining(item));
}
}
catch (IOException e)
{
throw new RuntimeIOException(e);
}
}
}
@Override
public boolean isFinished()

View File

@ -155,53 +155,6 @@ class HttpInputOverHTTP extends HttpInput<ByteBuffer> implements Callback
_content=item;
}
@Override
public void consumeAll()
{
final HttpParser parser = _httpConnection.getParser();
try
{
ByteBuffer requestBuffer = null;
while (!parser.isComplete())
{
_content=null;
_httpConnection.getParser().parseNext(requestBuffer==null?BufferUtil.EMPTY_BUFFER:requestBuffer);
if (parser.isComplete())
break;
if (BufferUtil.isEmpty(requestBuffer))
{
if ( _httpConnection.getEndPoint().isInputShutdown())
parser.atEOF();
else
{
requestBuffer=_httpConnection.getRequestBuffer();
if (BufferUtil.isEmpty(requestBuffer))
{
int filled=_httpConnection.getEndPoint().fill(requestBuffer);
if (filled==0)
filled=_httpConnection.getEndPoint().fill(requestBuffer);
if (filled<0)
_httpConnection.getParser().atEOF();
else if (filled==0)
{
blockForContent();
}
}
}
}
}
}
catch(IOException e)
{
LOG.ignore(e);
_httpConnection.getParser().atEOF();
}
}
@Override
protected void unready()
{

View File

@ -165,26 +165,4 @@ public abstract class QueuedHttpInput<T> extends HttpInput<T>
}
}
/* ------------------------------------------------------------ */
public void consumeAll()
{
synchronized (lock())
{
try
{
while (!isFinished())
{
T item = getNextContent();
if (item==null)
blockForContent();
else
consume(item,remaining(item));
}
}
catch (IOException e)
{
throw new RuntimeIOException(e);
}
}
}
}