use of org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState in project tomcat by apache.
the class AbstractProcessorLight method process.
@Override
public SocketState process(SocketWrapperBase<?> socketWrapper, SocketEvent status) throws IOException {
SocketState state = SocketState.CLOSED;
Iterator<DispatchType> dispatches = null;
do {
if (dispatches != null) {
DispatchType nextDispatch = dispatches.next();
state = dispatch(nextDispatch.getSocketStatus());
} else if (status == SocketEvent.DISCONNECT) {
// Do nothing here, just wait for it to get recycled
} else if (isAsync() || isUpgrade() || state == SocketState.ASYNC_END) {
state = dispatch(status);
if (state == SocketState.OPEN) {
// There may be pipe-lined data to read. If the data isn't
// processed now, execution will exit this loop and call
// release() which will recycle the processor (and input
// buffer) deleting any pipe-lined data. To avoid this,
// process it now.
state = service(socketWrapper);
}
} else if (status == SocketEvent.OPEN_WRITE) {
// Extra write event likely after async, ignore
state = SocketState.LONG;
} else {
state = service(socketWrapper);
}
if (state != SocketState.CLOSED && isAsync()) {
state = asyncPostProcess();
}
if (getLog().isDebugEnabled()) {
getLog().debug("Socket: [" + socketWrapper + "], Status in: [" + status + "], State out: [" + state + "]");
}
if (dispatches == null || !dispatches.hasNext()) {
// Only returns non-null iterator if there are
// dispatches to process.
dispatches = getIteratorAndClearDispatches();
}
} while (state == SocketState.ASYNC_END || dispatches != null && state != SocketState.CLOSED);
return state;
}
use of org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState in project tomcat by apache.
the class StreamProcessor method process.
final void process(SocketEvent event) {
try {
// FIXME: the regular processor syncs on socketWrapper, but here this deadlocks
synchronized (this) {
// HTTP/2 equivalent of AbstractConnectionHandler#process() without the
// socket <-> processor mapping
ContainerThreadMarker.set();
SocketState state = SocketState.CLOSED;
try {
state = process(socketWrapper, event);
if (state == SocketState.CLOSED) {
if (!getErrorState().isConnectionIoAllowed()) {
ConnectionException ce = new ConnectionException(sm.getString("streamProcessor.error.connection", stream.getConnectionId(), stream.getIdentifier()), Http2Error.INTERNAL_ERROR);
stream.close(ce);
} else if (!getErrorState().isIoAllowed()) {
StreamException se = new StreamException(sm.getString("streamProcessor.error.stream", stream.getConnectionId(), stream.getIdentifier()), Http2Error.INTERNAL_ERROR, stream.getIdentifier().intValue());
stream.close(se);
}
}
} catch (Exception e) {
ConnectionException ce = new ConnectionException(sm.getString("streamProcessor.error.connection", stream.getConnectionId(), stream.getIdentifier()), Http2Error.INTERNAL_ERROR);
ce.initCause(e);
stream.close(ce);
} finally {
ContainerThreadMarker.clear();
}
}
} finally {
handler.executeQueuedStream();
}
}
use of org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState in project tomcat by apache.
the class Http2UpgradeHandler method upgradeDispatch.
@Override
public SocketState upgradeDispatch(SocketEvent status) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("upgradeHandler.upgradeDispatch.entry", connectionId, status));
}
// WebConnection is not used so passing null here is fine
// Might not be necessary. init() will handle that.
init(null);
SocketState result = SocketState.CLOSED;
try {
pingManager.sendPing(false);
checkPauseState();
switch(status) {
case OPEN_READ:
try {
// There is data to read so use the read timeout while
// reading frames.
socketWrapper.setReadTimeout(getReadTimeout());
while (true) {
try {
if (!parser.readFrame(false)) {
break;
}
} catch (StreamException se) {
// Stream errors are not fatal to the connection so
// continue reading frames
Stream stream = getStream(se.getStreamId(), false);
if (stream == null) {
sendStreamReset(se);
} else {
stream.close(se);
}
}
}
// No more frames to read so switch to the keep-alive
// timeout.
socketWrapper.setReadTimeout(getKeepAliveTimeout());
} catch (Http2Exception ce) {
// Really ConnectionException
if (log.isDebugEnabled()) {
log.debug(sm.getString("upgradeHandler.connectionError"), ce);
}
closeConnection(ce);
break;
}
result = SocketState.UPGRADED;
break;
case OPEN_WRITE:
processWrites();
result = SocketState.UPGRADED;
break;
case DISCONNECT:
case ERROR:
case TIMEOUT:
case STOP:
close();
break;
}
} catch (IOException ioe) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("upgradeHandler.ioerror", connectionId), ioe);
}
close();
}
if (log.isDebugEnabled()) {
log.debug(sm.getString("upgradeHandler.upgradeDispatch.exit", connectionId, result));
}
return result;
}
Aggregations