From: fhanik Date: Wed, 10 Dec 2008 20:28:19 +0000 (+0000) Subject: implement timeout on sendfile write as wellimplement timeout on sendfile write as... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=92ef45ccb1589f1bc717fd01ed7c0c4887bb3c7e;p=tomcat7.0 implement timeout on sendfile write as wellimplement timeout on sendfile write as wellimplement timeout on sendfile write as wellimplement timeout on sendfile write as wellimplement timeout on sendfile write as wellimplement timeout on sendfile write as wellimplement timeout on sendfile write as wellimplement timeout on sendfile write as wellimplement timeout on sendfile write as well git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@725417 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/net/NioChannel.java b/java/org/apache/tomcat/util/net/NioChannel.java index aba04da39..92b90edc3 100644 --- a/java/org/apache/tomcat/util/net/NioChannel.java +++ b/java/org/apache/tomcat/util/net/NioChannel.java @@ -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() { diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index f3bf69be7..e7cfa17ed 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -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()); diff --git a/java/org/apache/tomcat/util/net/SecureNioChannel.java b/java/org/apache/tomcat/util/net/SecureNioChannel.java index 8f252039f..e32e48bd1 100644 --- a/java/org/apache/tomcat/util/net/SecureNioChannel.java +++ b/java/org/apache/tomcat/util/net/SecureNioChannel.java @@ -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; }