--- apache-tomcat-6.0.16-src/java/org/apache/coyote/http11/Http11NioProcessor.java 2008-01-28 16:41:12.000000000 -0600 +++ apache-tomcat-6.0.16-src/java/org/apache/coyote/http11/Http11NioProcessor.java 2008-06-05 11:58:29.000000000 -0500 @@ -908,6 +908,19 @@ } } + boolean doBreak = false; + + // Do sendfile as needed: add socket to sendfile and end + if (sendfileData != null && !error) { + KeyAttachment ka = (KeyAttachment)socket.getAttachment(false); + ka.setSendfileData(sendfileData); + 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); + doBreak = true; + } + // Finish the handling of the request if (!comet) { endRequest(); @@ -925,18 +938,10 @@ inputBuffer.nextRequest(); outputBuffer.nextRequest(); } - - // Do sendfile as needed: add socket to sendfile and end - if (sendfileData != null && !error) { - KeyAttachment ka = (KeyAttachment)socket.getAttachment(false); - ka.setSendfileData(sendfileData); - 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); - break; - } + if (doBreak) { + break; + } rp.setStage(org.apache.coyote.Constants.STAGE_KEEPALIVE); --- apache-tomcat-6.0.16-src/java/org/apache/tomcat/util/net/NioEndpoint.java 2008-01-28 16:41:14.000000000 -0600 +++ apache-tomcat-6.0.16-src/java/org/apache/tomcat/util/net/NioEndpoint.java 2008-06-05 11:53:54.000000000 -0500 @@ -30,6 +30,7 @@ import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; +import java.nio.channels.WritableByteChannel; import java.security.KeyStore; import java.util.Collection; import java.util.Iterator; @@ -926,8 +927,7 @@ } public boolean getUseSendfile() { - //send file doesn't work with SSL - return useSendfile && (!isSSLEnabled()); + return useSendfile; } public int getOomParachute() { @@ -1599,8 +1599,8 @@ } sd.fchannel = new FileInputStream(f).getChannel(); } - SocketChannel sc = attachment.getChannel().getIOChannel(); - long written = sd.fchannel.transferTo(sd.pos,sd.length,sc); + WritableByteChannel writableByteChannel = attachment.getChannel(); + long written = sd.fchannel.transferTo(sd.pos,sd.length,writableByteChannel); if ( written > 0 ) { sd.pos += written; sd.length -= written; --- apache-tomcat-6.0.16-src/java/org/apache/tomcat/util/net/SecureNioChannel.java 2008-01-28 16:41:14.000000000 -0600 +++ apache-tomcat-6.0.16-src/java/org/apache/tomcat/util/net/SecureNioChannel.java 2008-06-05 11:57:13.000000000 -0500 @@ -399,8 +399,6 @@ int written = sc.write(src); return written; } else { - //make sure we can handle expand, and that we only use on buffer - if ( src != bufHandler.getWriteBuffer() ) throw new IllegalArgumentException("You can only write using the application write buffer provided by the handler."); //are we closing or closed? if ( closing || closed) throw new IOException("Channel is in closing state.");