handle slow arriving input

This commit is contained in:
Greg Wilkins 2015-02-05 14:27:05 +11:00
parent 1576c68a52
commit d08fced010
1 changed files with 21 additions and 8 deletions

View File

@ -365,16 +365,29 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl
@Override
public void setReadListener(ReadListener readListener)
{
readListener = Objects.requireNonNull(readListener);
synchronized (lock())
try
{
if (_contentState != STREAM)
throw new IllegalStateException("state=" + _contentState);
_contentState = ASYNC;
_listener = readListener;
_notReady = true;
readListener = Objects.requireNonNull(readListener);
boolean content;
synchronized (lock())
{
if (_contentState != STREAM)
throw new IllegalStateException("state=" + _contentState);
_contentState = ASYNC;
_listener = readListener;
_notReady = true;
content = getNextContent()!=null;
}
if (content)
_channelState.onReadPossible();
else
unready();
}
catch(IOException e)
{
throw new RuntimeIOException(e);
}
_channelState.onReadPossible();
}
public void failed(Throwable x)