tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r1340215 - /tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Date Fri, 18 May 2012 19:23:13 GMT
Author: fhanik
Date: Fri May 18 19:23:12 2012
New Revision: 1340215

URL: http://svn.apache.org/viewvc?rev=1340215&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=52858
https://issues.apache.org/bugzilla/show_bug.cgi?id=53138
Fix broken NIO sendfile download
Fix high CPU usage due to registered OP_READ for sendfile processes


Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1340215&r1=1340214&r2=1340215&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri May 18 19:23:12 2012
@@ -1278,9 +1278,13 @@ public class NioEndpoint extends Abstrac
 
         public boolean processSendfile(SelectionKey sk, KeyAttachment attachment, boolean
reg, boolean event) {
             NioChannel sc = null;
+            if (log.isTraceEnabled()) {
+                log.trace("["+new java.sql.Date(System.currentTimeMillis()).toGMTString()+"]
Processing send file. ["+sk+"] ");
+            }
             try {
                 unreg(sk, attachment, sk.readyOps());
                 SendfileData sd = attachment.getSendfileData();
+                //setup the file channel
                 if ( sd.fchannel == null ) {
                     File f = new File(sd.fileName);
                     if ( !f.exists() ) {
@@ -1289,10 +1293,14 @@ public class NioEndpoint extends Abstrac
                     }
                     sd.fchannel = new FileInputStream(f).getChannel();
                 }
+
+                //configure output channel
                 sc = attachment.getChannel();
                 sc.setSendFile(true);
+                //ssl channel is slightly different
                 WritableByteChannel wc = ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel());
 
+                //we still have data in the buffer
                 if (sc.getOutboundRemaining()>0) {
                     if (sc.flushOutbound()) {
                         attachment.access();
@@ -1322,7 +1330,6 @@ public class NioEndpoint extends Abstrac
                     } catch (Exception ignore) {
                     }
                     if ( sd.keepAlive ) {
-                        if (reg) {
                             if (log.isDebugEnabled()) {
                                 log.debug("Connection is keep alive, registering back for
OP_READ");
                             }
@@ -1331,7 +1338,6 @@ public class NioEndpoint extends Abstrac
                             } else {
                                 reg(sk,attachment,SelectionKey.OP_READ);
                             }
-                        }
                     } else {
                         if (log.isDebugEnabled()) {
                             log.debug("Send file connection is being closed");
@@ -1339,7 +1345,7 @@ public class NioEndpoint extends Abstrac
                         cancelledKey(sk,SocketStatus.STOP);
                         return false;
                     }
-                } else if ( attachment.interestOps() == 0 && reg ) {
+                } else { //if ( attachment.interestOps() == 0 && reg ) {
                     if (log.isDebugEnabled()) {
                         log.debug("OP_WRITE for sendilfe:"+sd.fileName);
                     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message