implement timeout on sendfile write as wellimplement timeout on sendfile write as...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 10 Dec 2008 20:28:19 +0000 (20:28 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 10 Dec 2008 20:28:19 +0000 (20:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@725417 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/NioChannel.java
java/org/apache/tomcat/util/net/NioEndpoint.java
java/org/apache/tomcat/util/net/SecureNioChannel.java

index aba04da..92b90ed 100644 (file)
@@ -199,8 +199,13 @@ public class NioChannel implements ByteChannel{
         return 0;
     }
     
-    public void flushOutbound() throws IOException {
-        
+    /**
+     * Return true if the buffer wrote data
+     * @return
+     * @throws IOException
+     */
+    public boolean flushOutbound() throws IOException {
+        return false;
     }
     
     public boolean isSendFile() {
index f3bf69b..e7cfa17 100644 (file)
@@ -1577,12 +1577,15 @@ public class NioEndpoint {
                 WritableByteChannel wc =(WritableByteChannel) ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel());
                 
                 if (sc.getOutboundRemaining()>0) {
-                    sc.flushOutbound();
+                    if (sc.flushOutbound()) {
+                        attachment.access();
+                    }
                 } else {
                     long written = sd.fchannel.transferTo(sd.pos,sd.length,wc);
                     if ( written > 0 ) {
                         sd.pos += written;
                         sd.length -= written;
+                        attachment.access();
                     }
                 }
                 if ( sd.length <= 0 && sc.getOutboundRemaining()<=0) {
@@ -1662,13 +1665,14 @@ public class NioEndpoint {
                     if ( ka == null ) {
                         cancelledKey(key, SocketStatus.ERROR,false); //we don't support any keys without attachments
                     } else if ( ka.getError() ) {
-                        cancelledKey(key, SocketStatus.ERROR,true);
+                        cancelledKey(key, SocketStatus.ERROR,true);//TODO this is not yet being used
                     } else if (ka.getComet() && ka.getCometNotify() ) {
                         ka.setCometNotify(false);
                         reg(key,ka,0);//avoid multiple calls, this gets reregistered after invokation
                         //if (!processSocket(ka.getChannel(), SocketStatus.OPEN_CALLBACK)) processSocket(ka.getChannel(), SocketStatus.DISCONNECT);
                         if (!processSocket(ka.getChannel(), SocketStatus.OPEN, true)) processSocket(ka.getChannel(), SocketStatus.DISCONNECT, true);
-                    }else if ((ka.interestOps()&SelectionKey.OP_READ) == SelectionKey.OP_READ) {
+                    }else if ((ka.interestOps()&SelectionKey.OP_READ) == SelectionKey.OP_READ ||
+                              (ka.interestOps()&SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
                         //only timeout sockets that we are waiting for a read from
                         long delta = now - ka.getLastAccess();
                         long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout());
index 8f25203..e32e48b 100644 (file)
@@ -440,8 +440,11 @@ public class SecureNioChannel extends NioChannel  {
     }
     
     @Override
-    public void flushOutbound() throws IOException {
+    public boolean flushOutbound() throws IOException {
+        int remaining = netOutBuffer.remaining();
         flush(netOutBuffer);
+        int remaining2= netOutBuffer.remaining();
+        return remaining2 < remaining;
     }