Skip to content

Commit

Permalink
Use same handling for incomplete reads now all InputBuffers support
Browse files Browse the repository at this point in the history
non-blcoking reading of request line and headers. Pull method up into
base class to reduce duplication.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1651388 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jan 13, 2015
1 parent c63a6f6 commit 36cf18b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 86 deletions.
42 changes: 33 additions & 9 deletions java/org/apache/coyote/http11/AbstractHttp11Processor.java
Expand Up @@ -901,15 +901,6 @@ public final void action(ActionCode actionCode, Object param) {
abstract void actionInternal(ActionCode actionCode, Object param);


/**
* Defines how a connector handles an incomplete request line read.
*
* @return <code>true</code> if the processor should break out of the
* processing loop, otherwise <code>false</code>.
*/
protected abstract boolean handleIncompleteRequestLineRead();


/**
* Set the socket timeout.
*/
Expand Down Expand Up @@ -1145,6 +1136,39 @@ public SocketState process(SocketWrapperBase<S> socketWrapper)
}


private boolean handleIncompleteRequestLineRead() {
// Haven't finished reading the request so keep the socket
// open
openSocket = true;
// Check to see if we have read any of the request line yet
if (getInputBuffer().getParsingRequestLinePhase() < 1) {
if (keptAlive) {
// Haven't read the request line and have previously processed a
// request. Must be keep-alive. Make sure poller uses keepAlive.
socketWrapper.setTimeout(endpoint.getKeepAliveTimeout());
}
} else {
// Started to read request line.
if (request.getStartTime() < 0) {
request.setStartTime(System.currentTimeMillis());
}
if (endpoint.isPaused()) {
// Partially processed the request so need to respond
response.setStatus(503);
setErrorState(ErrorState.CLOSE_CLEAN, null);
getAdapter().log(request, response, 0);
return false;
} else {
// Need to keep processor associated with socket
readComplete = false;
// Make sure poller uses soTimeout from here onwards
socketWrapper.setTimeout(endpoint.getSoTimeout());
}
}
return true;
}


private void checkExpectationAndResponseStatus() {
if (expectation && (response.getStatus() < 200 || response.getStatus() > 299)) {
// Client sent Expect: 100-continue but received a
Expand Down
11 changes: 0 additions & 11 deletions java/org/apache/coyote/http11/Http11AprProcessor.java
Expand Up @@ -92,17 +92,6 @@ public Http11AprProcessor(int headerBufferSize, AbstractEndpoint<Long> endpoint,

// --------------------------------------------------------- Public Methods


@Override
protected boolean handleIncompleteRequestLineRead() {
// This means that no data is available right now
// (long keepalive), so that the processor should be recycled
// and the method should return true
openSocket = true;
return true;
}


@Override
protected void setSocketTimeout(int timeout) {
Socket.timeoutSet(socketWrapper.getSocket().longValue(), timeout * 1000);
Expand Down
35 changes: 0 additions & 35 deletions java/org/apache/coyote/http11/Http11Nio2Processor.java
Expand Up @@ -121,41 +121,6 @@ protected void resetTimeouts() {
}


@Override
protected boolean handleIncompleteRequestLineRead() {
// Haven't finished reading the request so keep the socket
// open
openSocket = true;
// Check to see if we have read any of the request line yet
if (((InternalNio2InputBuffer)
getInputBuffer()).getParsingRequestLinePhase() < 1) {
if (keptAlive) {
// Haven't read the request line and have previously processed a
// request. Must be keep-alive. Make sure poller uses keepAlive.
socketWrapper.setTimeout(endpoint.getKeepAliveTimeout());
}
} else {
// Started to read request line.
if (request.getStartTime() < 0) {
request.setStartTime(System.currentTimeMillis());
}
if (endpoint.isPaused()) {
// Partially processed the request so need to respond
response.setStatus(503);
setErrorState(ErrorState.CLOSE_CLEAN, null);
getAdapter().log(request, response, 0);
return false;
} else {
// Need to keep processor associated with socket
readComplete = false;
// Make sure poller uses soTimeout from here onwards
socketWrapper.setTimeout(endpoint.getSoTimeout());
}
}
return true;
}


@Override
protected void setSocketTimeout(int timeout) throws IOException {
socketWrapper.setTimeout(timeout);
Expand Down
31 changes: 0 additions & 31 deletions java/org/apache/coyote/http11/Http11NioProcessor.java
Expand Up @@ -115,37 +115,6 @@ protected void resetTimeouts() {
}


@Override
protected boolean handleIncompleteRequestLineRead() {
// Haven't finished reading the request so keep the socket
// open
openSocket = true;
// Check to see if we have read any of the request line yet
if (((InternalNioInputBuffer)
getInputBuffer()).getParsingRequestLinePhase() < 2) {
if (keptAlive) {
// Haven't read the request line and have previously processed a
// request. Must be keep-alive. Make sure poller uses keepAlive.
socketWrapper.setTimeout(endpoint.getKeepAliveTimeout());
}
} else {
if (endpoint.isPaused()) {
// Partially processed the request so need to respond
response.setStatus(503);
setErrorState(ErrorState.CLOSE_CLEAN, null);
getAdapter().log(request, response, 0);
return false;
} else {
// Need to keep processor associated with socket
readComplete = false;
// Make sure poller uses soTimeout from here onwards
socketWrapper.setTimeout(endpoint.getSoTimeout());
}
}
return true;
}


@Override
protected void setSocketTimeout(int timeout) throws IOException {
socketWrapper.getSocket().getIOChannel().socket().setSoTimeout(timeout);
Expand Down

0 comments on commit 36cf18b

Please sign in to comment.