You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/02/19 23:27:39 UTC
svn commit: r1731303 - in /tomcat/tc8.0.x/trunk/java/org/apache:
coyote/http11/Http11Nio2Processor.java
coyote/http11/Http11NioProcessor.java tomcat/util/net/Nio2Endpoint.java
tomcat/util/net/NioEndpoint.java tomcat/util/net/SendfileState.java
Author: markt
Date: Fri Feb 19 22:27:39 2016
New Revision: 1731303
URL: http://svn.apache.org/viewvc?rev=1731303&view=rev
Log:
Follow-up to r1731093.
There are three possible return values rather than two for processSendFile()
Added:
tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/SendfileState.java
- copied unchanged from r1731249, tomcat/trunk/java/org/apache/tomcat/util/net/SendfileState.java
Modified:
tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java
tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Modified: tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java?rev=1731303&r1=1731302&r2=1731303&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java Fri Feb 19 22:27:39 2016
@@ -275,17 +275,19 @@ public class Http11Nio2Processor extends
@Override
- protected boolean breakKeepAliveLoop(
- SocketWrapper<Nio2Channel> socketWrapper) {
+ protected boolean breakKeepAliveLoop(SocketWrapper<Nio2Channel> socketWrapper) {
openSocket = keepAlive;
// Do sendfile as needed: add socket to sendfile and end
if (sendfileData != null && !getErrorState().isError()) {
((Nio2Endpoint.Nio2SocketWrapper) socketWrapper).setSendfileData(sendfileData);
sendfileData.keepAlive = keepAlive;
- switch (((Nio2Endpoint) endpoint)
- .processSendfile((Nio2Endpoint.Nio2SocketWrapper) socketWrapper)) {
+ switch (((Nio2Endpoint) endpoint).processSendfile(
+ (Nio2Endpoint.Nio2SocketWrapper) socketWrapper)) {
case DONE:
return false;
+ case PENDING:
+ sendfileInProgress = true;
+ return true;
case ERROR:
// Write failed
if (log.isDebugEnabled()) {
@@ -293,9 +295,6 @@ public class Http11Nio2Processor extends
}
setErrorState(ErrorState.CLOSE_NOW, null);
return true;
- case PENDING:
- sendfileInProgress = true;
- return true;
}
}
return false;
Modified: tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1731303&r1=1731302&r2=1731303&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Fri Feb 19 22:27:39 2016
@@ -282,17 +282,23 @@ public class Http11NioProcessor extends
SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor(
socketWrapper.getSocket().getPoller().getSelector());
//do the first write on this thread, might as well
- if (socketWrapper.getSocket().getPoller().processSendfile(key,
- (KeyAttachment) socketWrapper, true)) {
+ switch (socketWrapper.getSocket().getPoller().processSendfile(
+ key, (KeyAttachment) socketWrapper, true)) {
+ case DONE:
+ // If sendfile is complete, no need to break keep-alive loop
+ sendfileData = null;
+ return false;
+ case PENDING:
sendfileInProgress = true;
- } else {
+ return true;
+ case ERROR:
// Write failed
if (log.isDebugEnabled()) {
log.debug(sm.getString("http11processor.sendfile.error"));
}
setErrorState(ErrorState.CLOSE_NOW, null);
+ return true;
}
- return true;
}
return false;
}
Modified: tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1731303&r1=1731302&r2=1731303&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Fri Feb 19 22:27:39 2016
@@ -873,10 +873,6 @@ public class Nio2Endpoint extends Abstra
TimeUnit.MILLISECONDS, socket, awaitBytes);
}
- public enum SendfileState {
- PENDING, DONE, ERROR
- }
-
private CompletionHandler<Integer, SendfileData> sendfile = new CompletionHandler<Integer, SendfileData>() {
@Override
Modified: tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1731303&r1=1731302&r2=1731303&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri Feb 19 22:27:39 2016
@@ -1140,7 +1140,7 @@ public class NioEndpoint extends Abstrac
return result;
}
- public boolean processSendfile(SelectionKey sk, KeyAttachment attachment,
+ public SendfileState processSendfile(SelectionKey sk, KeyAttachment attachment,
boolean calledByProcessor) {
NioChannel sc = null;
try {
@@ -1156,7 +1156,7 @@ public class NioEndpoint extends Abstrac
File f = new File(sd.fileName);
if (!f.exists()) {
cancelledKey(sk,SocketStatus.ERROR);
- return false;
+ return SendfileState.ERROR;
}
@SuppressWarnings("resource") // Closed when channel is closed
FileInputStream fis = new FileInputStream(f);
@@ -1211,9 +1211,9 @@ public class NioEndpoint extends Abstrac
log.debug("Send file connection is being closed");
}
cancelledKey(sk,SocketStatus.STOP);
- return false;
}
}
+ return SendfileState.DONE;
} else {
if (log.isDebugEnabled()) {
log.debug("OP_WRITE for sendfile: " + sd.fileName);
@@ -1223,17 +1223,17 @@ public class NioEndpoint extends Abstrac
} else {
reg(sk,attachment,SelectionKey.OP_WRITE);
}
+ return SendfileState.PENDING;
}
}catch ( IOException x ) {
if ( log.isDebugEnabled() ) log.debug("Unable to complete sendfile request:", x);
cancelledKey(sk,SocketStatus.ERROR);
- return false;
+ return SendfileState.ERROR;
}catch ( Throwable t ) {
log.error("",t);
cancelledKey(sk, SocketStatus.ERROR);
- return false;
+ return SendfileState.ERROR;
}
- return true;
}
protected void unreg(SelectionKey sk, KeyAttachment attachment, int readyOps) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org