Author: fhanik
Date: Wed Nov 19 15:39:17 2008
New Revision: 719129

URL: http://svn.apache.org/viewvc?rev=719129&view=rev
Log:
Fix SEND_FILE bug, with Java NIO you can only change the key interest ops on 
the poller thread, so we have to make sure we fire off an event

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

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=719129&r1=719128&r2=719129&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Wed Nov 
19 15:39:17 2008
@@ -921,7 +921,7 @@
                 sendfileData.keepAlive = keepAlive;
                 SelectionKey key = 
socket.getIOChannel().keyFor(socket.getPoller().getSelector());
                 //do the first write on this thread, might as well
-                openSocket = socket.getPoller().processSendfile(key,ka,true);
+                openSocket = 
socket.getPoller().processSendfile(key,ka,true,true);
                 break;
             }
 

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=719129&r1=719128&r2=719129&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed Nov 19 
15:39:17 2008
@@ -1547,7 +1547,7 @@
                     NioChannel channel = attachment.getChannel();
                     if (sk.isReadable() || sk.isWritable() ) {
                         if ( attachment.getSendfileData() != null ) {
-                            processSendfile(sk,attachment,true);
+                            processSendfile(sk,attachment,true, false);
                         } else if ( attachment.getComet() ) {
                             //check if thread is available
                             if ( isWorkerAvailable() ) {
@@ -1592,7 +1592,7 @@
             return result;
         }
         
-        public boolean processSendfile(SelectionKey sk, KeyAttachment 
attachment, boolean reg) {
+        public boolean processSendfile(SelectionKey sk, KeyAttachment 
attachment, boolean reg, boolean event) {
             try {
                 //unreg(sk,attachment);//only do this if we do process send 
file on a separate thread
                 SendfileData sd = attachment.getSendfileData();
@@ -1616,10 +1616,16 @@
                     }
                     attachment.setSendfileData(null);
                     if ( sd.keepAlive ) {
-                        if (log.isDebugEnabled()) {
-                            log.debug("Connection is keep alive, registering 
back for OP_READ");
+                        if (reg) {
+                            if (log.isDebugEnabled()) {
+                                log.debug("Connection is keep alive, 
registering back for OP_READ");
+                            }
+                            if (event) {
+                                
this.add(attachment.getChannel(),SelectionKey.OP_READ);
+                            } else {
+                                reg(sk,attachment,SelectionKey.OP_READ);
+                            }
                         }
-                        if (reg) reg(sk,attachment,SelectionKey.OP_READ);
                     } else {
                         if (log.isDebugEnabled()) {
                             log.debug("Send file connection is being closed");
@@ -1630,11 +1636,14 @@
                     if (log.isDebugEnabled()) {
                         log.debug("OP_WRITE for sendilfe:"+sd.fileName);
                     }
-
-                    reg(sk,attachment,SelectionKey.OP_WRITE);
+                    if (event) {
+                        add(attachment.getChannel(),SelectionKey.OP_WRITE);
+                    } else {
+                        reg(sk,attachment,SelectionKey.OP_WRITE);
+                    }
                 }
             }catch ( IOException x ) {
-                if ( log.isDebugEnabled() ) log.warn("Unable to complete 
sendfile request:", x);
+                if ( log.isDebugEnabled() ) log.debug("Unable to complete 
sendfile request:", x);
                 cancelledKey(sk,SocketStatus.ERROR,false);
                 return false;
             }catch ( Throwable t ) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to