From a255cfec0c4c4cc74ca1f29342235d290648d537 Mon Sep 17 00:00:00 2001 From: fhanik Date: Wed, 19 Nov 2008 23:39:17 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@719129 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/coyote/http11/Http11NioProcessor.java | 2 +- java/org/apache/tomcat/util/net/NioEndpoint.java | 25 +++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index 70a4784ab..425d8c486 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -921,7 +921,7 @@ public class Http11NioProcessor implements ActionHook { 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; } diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index ce5941a82..7ced0bafd 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1547,7 +1547,7 @@ public class NioEndpoint { 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 @@ public class NioEndpoint { 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 @@ public class NioEndpoint { } 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 @@ public class NioEndpoint { 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 ) { -- 2.11.0