Optimized sendfile a tiny bit. Instead of handing off to the poller, since we are...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 23 Mar 2007 15:28:39 +0000 (15:28 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 23 Mar 2007 15:28:39 +0000 (15:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@521765 13f79535-47bb-0310-9956-ffa450edef68

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

index 4b58aa7..8300d67 100644 (file)
@@ -936,8 +936,9 @@ public class Http11NioProcessor implements ActionHook {
                 KeyAttachment ka = (KeyAttachment)socket.getAttachment(false);
                 ka.setSendfileData(sendfileData);
                 sendfileData.keepAlive = keepAlive;
-                endpoint.getPoller0().add(socket,SelectionKey.OP_WRITE);
-                openSocket = true;
+                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);
                 break;
             }
 
index 474d550..33d5bca 100644 (file)
@@ -1406,7 +1406,7 @@ public class NioEndpoint {
                     NioChannel channel = attachment.getChannel();
                     if (sk.isReadable() || sk.isWritable() ) {
                         if ( attachment.getSendfileData() != null ) {
-                            processSendfile(sk,attachment);
+                            processSendfile(sk,attachment,true);
                         } else if ( attachment.getComet() ) {
                             //check if thread is available
                             if ( isWorkerAvailable() ) {
@@ -1451,7 +1451,7 @@ public class NioEndpoint {
             return result;
         }
         
-        protected void processSendfile(SelectionKey sk, KeyAttachment attachment) {
+        public boolean processSendfile(SelectionKey sk, KeyAttachment attachment, boolean reg) {
             try {
                 //unreg(sk,attachment);//only do this if we do process send file on a separate thread
                 SendfileData sd = attachment.getSendfileData();
@@ -1459,7 +1459,7 @@ public class NioEndpoint {
                     File f = new File(sd.fileName);
                     if ( !f.exists() ) {
                         cancelledKey(sk,SocketStatus.ERROR,false);
-                        return;
+                        return false;
                     }
                     sd.fchannel = new FileInputStream(f).getChannel();
                 }
@@ -1472,17 +1472,23 @@ public class NioEndpoint {
                 if ( sd.length <= 0 ) {
                     attachment.setSendfileData(null);
                     if ( sd.keepAlive ) 
-                        reg(sk,attachment,SelectionKey.OP_READ);
+                        if (reg) reg(sk,attachment,SelectionKey.OP_READ);
                     else 
                         cancelledKey(sk,SocketStatus.STOP,false);
+                } else if ( attachment.interestOps() == 0 && reg ) {
+                    reg(sk,attachment,SelectionKey.OP_WRITE);
                 }
             }catch ( IOException x ) {
-                if ( log.isDebugEnabled() ) log.warn("Unable to complete send file", x);
+                if ( log.isDebugEnabled() ) log.warn("Unable to complete sendfile request:", x);
+                else log.warn("Unable to complete sendfile request:"+x.getMessage());
                 cancelledKey(sk,SocketStatus.ERROR,false);
+                return false;
             }catch ( Throwable t ) {
                 log.error("",t);
                 cancelledKey(sk, SocketStatus.ERROR, false);
+                return false;
             }
+            return true;
         }
 
         protected void unreg(SelectionKey sk, KeyAttachment attachment) {