Index: java/org/apache/tomcat/util/net/NioBlockingSelector.java =================================================================== --- java/org/apache/tomcat/util/net/NioBlockingSelector.java (revision 585602) +++ java/org/apache/tomcat/util/net/NioBlockingSelector.java (working copy) @@ -47,10 +47,6 @@ boolean timedout = false; int keycount = 1; //assume we can write long time = System.currentTimeMillis(); //start the timeout timer - if (socket.getBufHandler().getWriteBuffer() != buf) { - socket.getBufHandler().getWriteBuffer().put(buf); - buf = socket.getBufHandler().getWriteBuffer(); - } try { while ( (!timedout) && buf.hasRemaining()) { if (keycount > 0) { //only write if we were registered for a write Index: java/org/apache/tomcat/util/net/NioSelectorPool.java =================================================================== --- java/org/apache/tomcat/util/net/NioSelectorPool.java (revision 585602) +++ java/org/apache/tomcat/util/net/NioSelectorPool.java (working copy) @@ -139,10 +139,6 @@ boolean timedout = false; int keycount = 1; //assume we can write long time = System.currentTimeMillis(); //start the timeout timer - if ( socket.getBufHandler().getWriteBuffer()!= buf ) { - socket.getBufHandler().getWriteBuffer().put(buf); - buf = socket.getBufHandler().getWriteBuffer(); - } try { while ( (!timedout) && buf.hasRemaining() ) { int cnt = 0; Index: java/org/apache/tomcat/util/net/SecureNioChannel.java =================================================================== --- java/org/apache/tomcat/util/net/SecureNioChannel.java (revision 585602) +++ java/org/apache/tomcat/util/net/SecureNioChannel.java (working copy) @@ -392,38 +392,44 @@ * @todo Implement this java.nio.channels.WritableByteChannel method */ public int write(ByteBuffer src) throws IOException { - //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."); - - //the number of bytes written - int written = 0; - - if (!flush(netOutBuffer)) { - //we haven't emptied out the buffer yet + if ( src == this.netOutBuffer ) { + //we can get here through a recursive call + //by using the NioBlockingSelector + 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."); + + //the number of bytes written + int written = 0; + + if (!flush(netOutBuffer)) { + //we haven't emptied out the buffer yet + return written; + } + + /* + * The data buffer is empty, we can reuse the entire buffer. + */ + netOutBuffer.clear(); + + SSLEngineResult result = sslEngine.wrap(src, netOutBuffer); + written = result.bytesConsumed(); + netOutBuffer.flip(); + + if (result.getStatus() == Status.OK) { + if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks(); + } else { + throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus()); + } + + //force a flush + flush(netOutBuffer); + return written; } - - /* - * The data buffer is empty, we can reuse the entire buffer. - */ - netOutBuffer.clear(); - - SSLEngineResult result = sslEngine.wrap(src, netOutBuffer); - written = result.bytesConsumed(); - netOutBuffer.flip(); - - if (result.getStatus() == Status.OK) { - if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) tasks(); - } else { - throw new IOException("Unable to wrap data, invalid engine state: " +result.getStatus()); - } - - //force a flush - flush(netOutBuffer); - - return written; } /**