import org.apache.tomcat.util.net.AbstractEndpoint;
import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
import org.apache.tomcat.util.net.SocketStatus;
+import org.apache.tomcat.util.net.SocketWrapper;
import org.apache.tomcat.util.res.StringManager;
public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> {
*/
protected boolean openSocket = false;
+
+ /**
+ * Flag that indicates that send file processing is in progress and that the
+ * socket should not be returned to the poller (where a poller is used).
+ */
+ protected boolean sendfileInProgress = false;
+
+
/**
* HTTP/1.1 flag.
*/
}
}
-
+
+
+ /**
+ * Checks to see of the keep-alive loop should be broken, performing any
+ * processing (e.g. send file handling) that may have an impact on whether
+ * or not the keep-alive loop should be broken.
+ * @return
+ */
+ protected abstract boolean breakKeepAliveLoop(
+ SocketWrapper<S> socketWrapper);
+
+
public final void recycle() {
getInputBuffer().recycle();
getOutputBuffer().recycle();
keepAlive = true;
comet = false;
openSocket = false;
+ sendfileInProgress = false;
int soTimeout = endpoint.getSoTimeout();
}
boolean keptAlive = false;
- boolean sendfileInProgress = false;
long socketRef = socketWrapper.getSocket().longValue();
rp.setStage(org.apache.coyote.Constants.STAGE_KEEPALIVE);
- // Do sendfile as needed: add socket to sendfile and end
- if (sendfileData != null && !error) {
- sendfileData.socket = socketRef;
- sendfileData.keepAlive = keepAlive;
- if (!((AprEndpoint)endpoint).getSendfile().add(sendfileData)) {
- // Didn't send all of the data to sendfile.
- if (sendfileData.socket == 0) {
- // The socket is no longer set. Something went wrong.
- // Close the connection. Too late to set status code.
- if (log.isDebugEnabled()) {
- log.debug(sm.getString(
- "http11processor.sendfile.error"));
- }
- error = true;
- } else {
- // The sendfile Poller will add the socket to the main
- // Poller once sendfile processing is complete
- sendfileInProgress = true;
- }
- break;
- }
+ if (breakKeepAliveLoop(socketWrapper)) {
+ break;
}
}
@Override
+ protected boolean breakKeepAliveLoop(SocketWrapper<Long> socketWrapper) {
+ // Do sendfile as needed: add socket to sendfile and end
+ if (sendfileData != null && !error) {
+ sendfileData.socket = socketWrapper.getSocket().longValue();
+ sendfileData.keepAlive = keepAlive;
+ if (!((AprEndpoint)endpoint).getSendfile().add(sendfileData)) {
+ // Didn't send all of the data to sendfile.
+ if (sendfileData.socket == 0) {
+ // The socket is no longer set. Something went wrong.
+ // Close the connection. Too late to set status code.
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString(
+ "http11processor.sendfile.error"));
+ }
+ error = true;
+ } else {
+ // The sendfile Poller will add the socket to the main
+ // Poller once sendfile processing is complete
+ sendfileInProgress = true;
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ @Override
protected boolean disableKeepAlive() {
return false;
}
keepAlive = true;
comet = false;
openSocket = false;
+ sendfileInProgress = false;
int soTimeout = endpoint.getSoTimeout();
rp.setStage(org.apache.coyote.Constants.STAGE_KEEPALIVE);
- // Do sendfile as needed: add socket to sendfile and end
- if (sendfileData != null && !error) {
- ((KeyAttachment) socketWrapper).setSendfileData(sendfileData);
- sendfileData.keepAlive = keepAlive;
- SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor(
- socketWrapper.getSocket().getPoller().getSelector());
- //do the first write on this thread, might as well
- openSocket = socketWrapper.getSocket().getPoller().processSendfile(key,
- (KeyAttachment) socketWrapper, true, true);
- break;
+ if (breakKeepAliveLoop(socketWrapper)) {
+ break;
}
}
} else {
return (openSocket) ? (readComplete?SocketState.OPEN:SocketState.LONG) : SocketState.CLOSED;
}
+ }
+
+ @Override
+ protected boolean breakKeepAliveLoop(
+ SocketWrapper<NioChannel> socketWrapper) {
+ // Do sendfile as needed: add socket to sendfile and end
+ if (sendfileData != null && !error) {
+ ((KeyAttachment) socketWrapper).setSendfileData(sendfileData);
+ sendfileData.keepAlive = keepAlive;
+ SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor(
+ socketWrapper.getSocket().getPoller().getSelector());
+ //do the first write on this thread, might as well
+ openSocket = socketWrapper.getSocket().getPoller().processSendfile(key,
+ (KeyAttachment) socketWrapper, true, true);
+ return true;
+ }
+ return false;
}
keepAlive = true;
comet = false;
openSocket = false;
+ sendfileInProgress = false;
int soTimeout = endpoint.getSoTimeout();
rp.setStage(org.apache.coyote.Constants.STAGE_KEEPALIVE);
- // If we don't have a pipe-lined request allow this thread to be
- // used by another connection
- if (isAsync() || error || inputBuffer.lastValid == 0) {
- break;
+ if (breakKeepAliveLoop(socketWrapper)) {
+ break;
}
}
}
}
}
-
+
+
+ @Override
+ protected boolean breakKeepAliveLoop(SocketWrapper<Socket> socketWrapper) {
+ // If we don't have a pipe-lined request allow this thread to be
+ // used by another connection
+ if (isAsync() || error || inputBuffer.lastValid == 0) {
+ return true;
+ }
+ return false;
+ }
+
@Override
protected boolean disableKeepAlive() {