Author: remy.maucherat(a)jboss.com
Date: 2015-03-11 11:23:29 -0400 (Wed, 11 Mar 2015)
New Revision: 2597
Modified:
branches/7.5.x/src/main/java/org/apache/tomcat/util/net/jsse/SecureNioChannel.java
Log:
BZ1200276 (to be confirmed): port Tomcat code to handle incomplete writes and special
cases.
Modified:
branches/7.5.x/src/main/java/org/apache/tomcat/util/net/jsse/SecureNioChannel.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/tomcat/util/net/jsse/SecureNioChannel.java 2015-02-20
09:56:23 UTC (rev 2596)
+++
branches/7.5.x/src/main/java/org/apache/tomcat/util/net/jsse/SecureNioChannel.java 2015-03-11
15:23:29 UTC (rev 2597)
@@ -20,6 +20,7 @@
import static org.jboss.web.CoyoteMessages.MESSAGES;
+import java.io.EOFException;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
@@ -321,7 +322,7 @@
* java.nio.channels.CompletionHandler)
*/
@Override
- public <A> void write(final ByteBuffer src, long timeout, TimeUnit unit, final A
attachment,
+ public <A> void write(final ByteBuffer src, final long timeout, final TimeUnit
unit, final A attachment,
final CompletionHandler<Integer, ? super A> handler) {
// The handshake is completed
@@ -340,13 +341,18 @@
@Override
public void completed(Integer nBytes, A attach) {
- if (nBytes < 0) {
- handler.failed(new ClosedChannelException(), attach);
- } else {
- // Call the handler completed method with the
- // consumed bytes number
- handler.completed(written, attach);
- }
+ if (nBytes.intValue() < 0) {
+ failed(new EOFException(), attach);
+ } else if (netOutBuffer.hasRemaining()) {
+ channel.write(netOutBuffer, timeout, unit, attachment,
this);
+ } else if (written == 0) {
+ // Special case, start over to avoid code duplication
+ write(src, timeout, unit, attachment, handler);
+ } else {
+ // Call the handler completed method with the
+ // consumed bytes number
+ handler.completed(Integer.valueOf(written), attach);
+ }
}
@Override
Show replies by date