Skip to content

Commit

Permalink
Pull up sendfileData instance and breakKeepAliveLoop method
Browse files Browse the repository at this point in the history
This also enabled the removal of recycleInternal()

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1654324 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jan 23, 2015
1 parent 0e27cf0 commit 1af65a6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 129 deletions.
37 changes: 32 additions & 5 deletions java/org/apache/coyote/http11/AbstractHttp11Processor.java
Expand Up @@ -53,6 +53,7 @@
import org.apache.tomcat.util.net.AbstractEndpoint; import org.apache.tomcat.util.net.AbstractEndpoint;
import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
import org.apache.tomcat.util.net.DispatchType; import org.apache.tomcat.util.net.DispatchType;
import org.apache.tomcat.util.net.SendfileDataBase;
import org.apache.tomcat.util.net.SocketStatus; import org.apache.tomcat.util.net.SocketStatus;
import org.apache.tomcat.util.net.SocketWrapperBase; import org.apache.tomcat.util.net.SocketWrapperBase;
import org.apache.tomcat.util.res.StringManager; import org.apache.tomcat.util.res.StringManager;
Expand Down Expand Up @@ -227,6 +228,12 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> {
protected HttpUpgradeHandler httpUpgradeHandler = null; protected HttpUpgradeHandler httpUpgradeHandler = null;




/**
* Sendfile data.
*/
protected SendfileDataBase sendfileData = null;


public AbstractHttp11Processor(int maxHttpHeaderSize, AbstractEndpoint<S> endpoint, public AbstractHttp11Processor(int maxHttpHeaderSize, AbstractEndpoint<S> endpoint,
int maxTrailerSize, int maxExtensionSize, int maxSwallowSize) { int maxTrailerSize, int maxExtensionSize, int maxSwallowSize) {


Expand Down Expand Up @@ -1769,10 +1776,32 @@ public void endRequest() {
* Checks to see if the keep-alive loop should be broken, performing any * Checks to see if the keep-alive loop should be broken, performing any
* processing (e.g. sendfile handling) that may have an impact on whether * processing (e.g. sendfile handling) that may have an impact on whether
* or not the keep-alive loop should be broken. * or not the keep-alive loop should be broken.
*
* @return true if the keep-alive loop should be broken * @return true if the keep-alive loop should be broken
*/ */
protected abstract boolean breakKeepAliveLoop( protected boolean breakKeepAliveLoop(SocketWrapperBase<S> socketWrapper) {
SocketWrapperBase<S> socketWrapper); openSocket = keepAlive;
// Do sendfile as needed: add socket to sendfile and end
if (sendfileData != null && !getErrorState().isError()) {
sendfileData.keepAlive = keepAlive;
switch (socketWrapper.processSendfile(sendfileData)) {
case DONE:
// If sendfile is complete, no need to break keep-alive loop
return false;
case PENDING:
sendfileInProgress = true;
return true;
case ERROR:
// Write failed
if (getLog().isDebugEnabled()) {
getLog().debug(sm.getString("http11processor.sendfile.error"));
}
setErrorState(ErrorState.CLOSE_NOW, null);
return true;
}
}
return false;
}




@Override @Override
Expand All @@ -1791,11 +1820,9 @@ public final void recycle() {
httpUpgradeHandler = null; httpUpgradeHandler = null;
resetErrorState(); resetErrorState();
socketWrapper = null; socketWrapper = null;
recycleInternal(); sendfileData = null;
} }


protected abstract void recycleInternal();



@Override @Override
public ByteBuffer getLeftoverInput() { public ByteBuffer getLeftoverInput() {
Expand Down
40 changes: 0 additions & 40 deletions java/org/apache/coyote/http11/Http11AprProcessor.java
Expand Up @@ -21,7 +21,6 @@
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;


import org.apache.coyote.ActionCode; import org.apache.coyote.ActionCode;
import org.apache.coyote.ErrorState;
import org.apache.coyote.http11.filters.BufferedInputFilter; import org.apache.coyote.http11.filters.BufferedInputFilter;
import org.apache.juli.logging.Log; import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory; import org.apache.juli.logging.LogFactory;
Expand All @@ -33,7 +32,6 @@
import org.apache.tomcat.util.net.AbstractEndpoint; import org.apache.tomcat.util.net.AbstractEndpoint;
import org.apache.tomcat.util.net.AprEndpoint; import org.apache.tomcat.util.net.AprEndpoint;
import org.apache.tomcat.util.net.SSLSupport; import org.apache.tomcat.util.net.SSLSupport;
import org.apache.tomcat.util.net.SocketWrapperBase;




/** /**
Expand Down Expand Up @@ -62,12 +60,6 @@ public Http11AprProcessor(int maxHttpHeaderSize, AbstractEndpoint<Long> endpoint


// ----------------------------------------------------- Instance Variables // ----------------------------------------------------- Instance Variables


/**
* Sendfile data.
*/
protected AprEndpoint.SendfileData sendfileData = null;


/** /**
* When client certificate information is presented in a form other than * When client certificate information is presented in a form other than
* instances of {@link java.security.cert.X509Certificate} it needs to be * instances of {@link java.security.cert.X509Certificate} it needs to be
Expand All @@ -90,32 +82,6 @@ protected void setSocketTimeout(int timeout) {
} }




@Override
protected boolean breakKeepAliveLoop(SocketWrapperBase<Long> socketWrapper) {
openSocket = keepAlive;
// Do sendfile as needed: add socket to sendfile and end
if (sendfileData != null && !getErrorState().isError()) {
sendfileData.keepAlive = keepAlive;
switch (socketWrapper.processSendfile(sendfileData)) {
case DONE:
// If sendfile is complete, no need to break keep-alive loop
return false;
case PENDING:
sendfileInProgress = true;
return true;
case ERROR:
// Write failed
if (log.isDebugEnabled()) {
log.debug(sm.getString("http11processor.sendfile.error"));
}
setErrorState(ErrorState.CLOSE_NOW, null);
return true;
}
}
return false;
}


@Override @Override
protected void registerForEvent(boolean read, boolean write) { protected void registerForEvent(boolean read, boolean write) {
((AprEndpoint) endpoint).getPoller().add( ((AprEndpoint) endpoint).getPoller().add(
Expand All @@ -129,12 +95,6 @@ protected void resetTimeouts() {
} }




@Override
public void recycleInternal() {
sendfileData = null;
}


@Override @Override
public void setSslSupport(SSLSupport sslSupport) { public void setSslSupport(SSLSupport sslSupport) {
// NOOP for APR // NOOP for APR
Expand Down
42 changes: 0 additions & 42 deletions java/org/apache/coyote/http11/Http11Nio2Processor.java
Expand Up @@ -23,7 +23,6 @@
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;


import org.apache.coyote.ActionCode; import org.apache.coyote.ActionCode;
import org.apache.coyote.ErrorState;
import org.apache.coyote.http11.filters.BufferedInputFilter; import org.apache.coyote.http11.filters.BufferedInputFilter;
import org.apache.juli.logging.Log; import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory; import org.apache.juli.logging.LogFactory;
Expand All @@ -34,7 +33,6 @@
import org.apache.tomcat.util.net.SSLSupport; import org.apache.tomcat.util.net.SSLSupport;
import org.apache.tomcat.util.net.SecureNio2Channel; import org.apache.tomcat.util.net.SecureNio2Channel;
import org.apache.tomcat.util.net.SocketStatus; import org.apache.tomcat.util.net.SocketStatus;
import org.apache.tomcat.util.net.SocketWrapperBase;




/** /**
Expand Down Expand Up @@ -64,14 +62,6 @@ public Http11Nio2Processor(int maxHttpHeaderSize, AbstractEndpoint<Nio2Channel>
} }




// ----------------------------------------------------- Instance Variables

/**
* Sendfile data.
*/
protected Nio2Endpoint.SendfileData sendfileData = null;


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


@Override @Override
Expand Down Expand Up @@ -119,38 +109,6 @@ protected void setSocketTimeout(int timeout) throws IOException {
} }




@Override
protected boolean breakKeepAliveLoop(SocketWrapperBase<Nio2Channel> socketWrapper) {
openSocket = keepAlive;
// Do sendfile as needed: add socket to sendfile and end
if (sendfileData != null && !getErrorState().isError()) {
sendfileData.keepAlive = keepAlive;
switch (socketWrapper.processSendfile(sendfileData)) {
case DONE:
// If sendfile is complete, no need to break keep-alive loop
return false;
case PENDING:
sendfileInProgress = true;
return true;
case ERROR:
// Write failed
if (log.isDebugEnabled()) {
log.debug(sm.getString("http11processor.sendfile.error"));
}
setErrorState(ErrorState.CLOSE_NOW, null);
return true;
}
}
return false;
}


@Override
public void recycleInternal() {
sendfileData = null;
}


// ----------------------------------------------------- ActionHook Methods // ----------------------------------------------------- ActionHook Methods


/** /**
Expand Down
42 changes: 0 additions & 42 deletions java/org/apache/coyote/http11/Http11NioProcessor.java
Expand Up @@ -23,7 +23,6 @@
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;


import org.apache.coyote.ActionCode; import org.apache.coyote.ActionCode;
import org.apache.coyote.ErrorState;
import org.apache.coyote.http11.filters.BufferedInputFilter; import org.apache.coyote.http11.filters.BufferedInputFilter;
import org.apache.juli.logging.Log; import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory; import org.apache.juli.logging.LogFactory;
Expand All @@ -32,7 +31,6 @@
import org.apache.tomcat.util.net.NioEndpoint; import org.apache.tomcat.util.net.NioEndpoint;
import org.apache.tomcat.util.net.SSLSupport; import org.apache.tomcat.util.net.SSLSupport;
import org.apache.tomcat.util.net.SecureNioChannel; import org.apache.tomcat.util.net.SecureNioChannel;
import org.apache.tomcat.util.net.SocketWrapperBase;




/** /**
Expand Down Expand Up @@ -64,14 +62,6 @@ public Http11NioProcessor(int maxHttpHeaderSize, AbstractEndpoint<NioChannel> en
} }




// ----------------------------------------------------- Instance Variables

/**
* Sendfile data.
*/
protected NioEndpoint.SendfileData sendfileData = null;


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


@Override @Override
Expand Down Expand Up @@ -112,38 +102,6 @@ protected void setSocketTimeout(int timeout) throws IOException {
} }




@Override
protected boolean breakKeepAliveLoop(SocketWrapperBase<NioChannel> socketWrapper) {
openSocket = keepAlive;
// Do sendfile as needed: add socket to sendfile and end
if (sendfileData != null && !getErrorState().isError()) {
sendfileData.keepAlive = keepAlive;
switch (socketWrapper.processSendfile(sendfileData)) {
case DONE:
// If sendfile is complete, no need to break keep-alive loop
return false;
case PENDING:
sendfileInProgress = true;
return true;
case ERROR:
// Write failed
if (log.isDebugEnabled()) {
log.debug(sm.getString("http11processor.sendfile.error"));
}
setErrorState(ErrorState.CLOSE_NOW, null);
return true;
}
}
return false;
}


@Override
public void recycleInternal() {
sendfileData = null;
}


// ----------------------------------------------------- ActionHook Methods // ----------------------------------------------------- ActionHook Methods


/** /**
Expand Down

0 comments on commit 1af65a6

Please sign in to comment.