Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x

This commit is contained in:
Greg Wilkins 2017-02-08 16:33:10 +11:00
commit a8bc125f5c
3 changed files with 56 additions and 27 deletions

View File

@ -99,6 +99,23 @@ public class HttpChannelState
ERRORED // The error has been processed ERRORED // The error has been processed
} }
public enum Interest
{
NONE(false),
NEEDED(true),
INTERESTED(true);
final boolean _interested;
boolean isInterested() { return _interested;}
boolean notInterested() { return !_interested;}
Interest(boolean interest)
{
_interested = interest;
}
}
private final boolean DEBUG=LOG.isDebugEnabled(); private final boolean DEBUG=LOG.isDebugEnabled();
private final Locker _locker=new Locker(); private final Locker _locker=new Locker();
private final HttpChannel _channel; private final HttpChannel _channel;
@ -108,8 +125,8 @@ public class HttpChannelState
private Async _async; private Async _async;
private boolean _initial; private boolean _initial;
private boolean _asyncReadPossible; private boolean _asyncReadPossible;
private boolean _asyncReadUnready; private Interest _asyncRead=Interest.NONE;
private boolean _asyncWrite; // TODO refactor same as read private boolean _asyncWritePossible;
private long _timeoutMs=DEFAULT_TIMEOUT; private long _timeoutMs=DEFAULT_TIMEOUT;
private AsyncContextEvent _event; private AsyncContextEvent _event;
@ -174,9 +191,15 @@ public class HttpChannelState
public String toStringLocked() public String toStringLocked()
{ {
return String.format("%s@%x{s=%s a=%s i=%b r=%s w=%b}",getClass().getSimpleName(),hashCode(),_state,_async,_initial, return String.format("%s@%x{s=%s a=%s i=%b r=%s/%s w=%b}",
_asyncReadPossible?(_asyncReadUnready?"PU":"P!U"):(_asyncReadUnready?"!PU":"!P!U"), getClass().getSimpleName(),
_asyncWrite); hashCode(),
_state,
_async,
_initial,
_asyncRead,
_asyncReadPossible,
_asyncWritePossible);
} }
@ -215,17 +238,17 @@ public class HttpChannelState
return Action.TERMINATED; return Action.TERMINATED;
case ASYNC_WOKEN: case ASYNC_WOKEN:
if (_asyncReadPossible) if (_asyncRead.isInterested() && _asyncReadPossible)
{ {
_state=State.ASYNC_IO; _state=State.ASYNC_IO;
_asyncReadUnready=false; _asyncRead=Interest.NONE;
return Action.READ_CALLBACK; return Action.READ_CALLBACK;
} }
if (_asyncWrite) if (_asyncWritePossible)
{ {
_state=State.ASYNC_IO; _state=State.ASYNC_IO;
_asyncWrite=false; _asyncWritePossible=false;
return Action.WRITE_CALLBACK; return Action.WRITE_CALLBACK;
} }
@ -409,24 +432,27 @@ public class HttpChannelState
break; break;
case STARTED: case STARTED:
if (_asyncReadUnready && _asyncReadPossible) if (_asyncRead.isInterested() && _asyncReadPossible)
{ {
_state=State.ASYNC_IO; _state=State.ASYNC_IO;
_asyncReadUnready=false; _asyncRead=Interest.NONE;
action = Action.READ_CALLBACK; action=Action.READ_CALLBACK;
} }
else if (_asyncWrite) // TODO refactor same as read else if (_asyncWritePossible)
{ {
_asyncWrite=false;
_state=State.ASYNC_IO; _state=State.ASYNC_IO;
_asyncWritePossible=false;
action=Action.WRITE_CALLBACK; action=Action.WRITE_CALLBACK;
} }
else else
{ {
_state=State.ASYNC_WAIT; _state=State.ASYNC_WAIT;
action=Action.WAIT; action=Action.WAIT;
if (_asyncReadUnready) if (_asyncRead==Interest.NEEDED)
{
_asyncRead=Interest.INTERESTED;
read_interested=true; read_interested=true;
}
Scheduler scheduler=_channel.getScheduler(); Scheduler scheduler=_channel.getScheduler();
if (scheduler!=null && _timeoutMs>0) if (scheduler!=null && _timeoutMs>0)
_event.setTimeoutTask(scheduler.schedule(_event,_timeoutMs,TimeUnit.MILLISECONDS)); _event.setTimeoutTask(scheduler.schedule(_event,_timeoutMs,TimeUnit.MILLISECONDS));
@ -895,8 +921,9 @@ public class HttpChannelState
_state=State.IDLE; _state=State.IDLE;
_async=Async.NOT_ASYNC; _async=Async.NOT_ASYNC;
_initial=true; _initial=true;
_asyncReadPossible=_asyncReadUnready=false; _asyncReadPossible=false;
_asyncWrite=false; _asyncRead=Interest.NONE;
_asyncWritePossible=false;
_timeoutMs=DEFAULT_TIMEOUT; _timeoutMs=DEFAULT_TIMEOUT;
_event=null; _event=null;
} }
@ -922,8 +949,9 @@ public class HttpChannelState
_state=State.UPGRADED; _state=State.UPGRADED;
_async=Async.NOT_ASYNC; _async=Async.NOT_ASYNC;
_initial=true; _initial=true;
_asyncReadPossible=_asyncReadUnready=false; _asyncReadPossible=false;
_asyncWrite=false; _asyncRead=Interest.NONE;
_asyncWritePossible=false;
_timeoutMs=DEFAULT_TIMEOUT; _timeoutMs=DEFAULT_TIMEOUT;
_event=null; _event=null;
} }
@ -1113,12 +1141,16 @@ public class HttpChannelState
LOG.debug("onReadUnready {}",toStringLocked()); LOG.debug("onReadUnready {}",toStringLocked());
// We were already unready, this is not a state change, so do nothing // We were already unready, this is not a state change, so do nothing
if (!_asyncReadUnready) if (_asyncRead!=Interest.INTERESTED)
{ {
_asyncReadUnready=true;
_asyncReadPossible=false; // Assumes this has been checked in isReady() with lock held _asyncReadPossible=false; // Assumes this has been checked in isReady() with lock held
if (_state==State.ASYNC_WAIT) if (_state==State.ASYNC_WAIT)
{
interested=true; interested=true;
_asyncRead=Interest.INTERESTED;
}
else
_asyncRead=Interest.NEEDED;
} }
} }
@ -1142,7 +1174,7 @@ public class HttpChannelState
LOG.debug("onReadPossible {}",toStringLocked()); LOG.debug("onReadPossible {}",toStringLocked());
_asyncReadPossible=true; _asyncReadPossible=true;
if (_state==State.ASYNC_WAIT && _asyncReadUnready) if (_state==State.ASYNC_WAIT && _asyncRead.isInterested())
{ {
woken=true; woken=true;
_state=State.ASYNC_WOKEN; _state=State.ASYNC_WOKEN;
@ -1166,7 +1198,6 @@ public class HttpChannelState
if(DEBUG) if(DEBUG)
LOG.debug("onReadReady {}",toStringLocked()); LOG.debug("onReadReady {}",toStringLocked());
_asyncReadUnready=true;
_asyncReadPossible=true; _asyncReadPossible=true;
if (_state==State.ASYNC_WAIT) if (_state==State.ASYNC_WAIT)
{ {
@ -1219,7 +1250,7 @@ public class HttpChannelState
if(DEBUG) if(DEBUG)
LOG.debug("onWritePossible {}",toStringLocked()); LOG.debug("onWritePossible {}",toStringLocked());
_asyncWrite=true; _asyncWritePossible=true;
if (_state==State.ASYNC_WAIT) if (_state==State.ASYNC_WAIT)
{ {
_state=State.ASYNC_WOKEN; _state=State.ASYNC_WOKEN;

View File

@ -551,7 +551,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
public void asyncReadFillInterested() public void asyncReadFillInterested()
{ {
getEndPoint().tryFillInterested(_asyncReadCallback); getEndPoint().fillInterested(_asyncReadCallback);
} }
public void blockingReadFillInterested() public void blockingReadFillInterested()

View File

@ -300,8 +300,6 @@ public class ServerConnector extends AbstractNetworkConnector
_localPort = serverChannel.socket().getLocalPort(); _localPort = serverChannel.socket().getLocalPort();
if (_localPort <= 0) if (_localPort <= 0)
throw new IOException("Server channel not bound"); throw new IOException("Server channel not bound");
addBean(serverChannel);
} }
serverChannel.configureBlocking(true); serverChannel.configureBlocking(true);