Author: remm Date: Fri Mar 14 15:21:26 2014 New Revision: 1577569 URL: http://svn.apache.org/r1577569 Log: Add missing code to retry if no bytes are written (handshake) like for blocking IO, and use EOFException instead.
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SecureNio2Channel.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SecureNio2Channel.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SecureNio2Channel.java?rev=1577569&r1=1577568&r2=1577569&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/SecureNio2Channel.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/SecureNio2Channel.java Fri Mar 14 15:21:26 2014 @@ -20,7 +20,6 @@ import java.io.EOFException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.AsynchronousSocketChannel; -import java.nio.channels.ClosedChannelException; import java.nio.channels.CompletionHandler; import java.nio.channels.WritePendingException; import java.util.concurrent.ExecutionException; @@ -665,7 +664,7 @@ public class SecureNio2Channel extends N @Override public void completed(Integer nBytes, A attach) { if (nBytes.intValue() < 0) { - handler.failed(new ClosedChannelException(), attach); + handler.failed(new EOFException(), attach); return; } try { @@ -734,8 +733,8 @@ public class SecureNio2Channel extends N } @Override - public <A> void write(final ByteBuffer src, long timeout, TimeUnit unit, final A attachment, - final CompletionHandler<Integer, ? super A> handler) { + public <A> void write(final ByteBuffer src, final long timeout, final TimeUnit unit, + final A attachment, final CompletionHandler<Integer, ? super A> handler) { //are we closing or closed? if (closing || closed) { handler.failed(new IOException("Channel is in closing state."), attachment); @@ -746,7 +745,7 @@ public class SecureNio2Channel extends N // Prepare the output buffer this.netOutBuffer.clear(); // Wrap the source data into the internal buffer - SSLEngineResult result = sslEngine.wrap(bufHandler.getWriteBuffer(), netOutBuffer); + SSLEngineResult result = sslEngine.wrap(src, netOutBuffer); final int written = result.bytesConsumed(); netOutBuffer.flip(); if (result.getStatus() == Status.OK) { @@ -762,7 +761,9 @@ public class SecureNio2Channel extends N @Override public void completed(Integer nBytes, A attach) { if (nBytes.intValue() < 0) { - handler.failed(new ClosedChannelException(), attach); + handler.failed(new EOFException(), attach); + } else if (written == 0) { + write(src, timeout, unit, attachment, handler); } else { // Call the handler completed method with the // consumed bytes number @@ -811,7 +812,7 @@ public class SecureNio2Channel extends N @Override public void completed(Integer nBytes, GatherState<A> attachment) { if (nBytes.intValue() < 0) { - state.handler.failed(new ClosedChannelException(), state.attachment); + state.handler.failed(new EOFException(), state.attachment); } else { if (state.pos == state.offset + state.length) { state.handler.completed(Long.valueOf(state.writeCount), state.attachment); @@ -822,7 +823,8 @@ public class SecureNio2Channel extends N netOutBuffer.clear(); // Wrap the source data into the internal buffer SSLEngineResult result = sslEngine.wrap(state.srcs[state.offset], netOutBuffer); - state.writeCount += result.bytesConsumed(); + int written = result.bytesConsumed(); + state.writeCount += written; netOutBuffer.flip(); if (result.getStatus() == Status.OK) { if (result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) @@ -831,7 +833,9 @@ public class SecureNio2Channel extends N failed(new IOException("Unable to wrap data, invalid engine state: " +result.getStatus()), attachment); return; } - state.offset++; + if (written > 0) { + state.offset++; + } // Write data to the channel sc.write(netOutBuffer, state.timeout, state.unit, state, this); } catch (Throwable exp) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org