Author: markt
Date: Fri Oct 23 13:10:07 2015
New Revision: 1710204

URL: http://svn.apache.org/viewvc?rev=1710204&view=rev
Log:
Use explicit rather than anonymous inner classes for the handshake completion 
handlers since that makes it easier to read debug traces.

Minor formatting fixes

Add a (possibly temporary) workaround for Chrome+NIO2

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=1710204&r1=1710203&r2=1710204&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SecureNio2Channel.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SecureNio2Channel.java Fri Oct 
23 13:10:07 2015
@@ -81,36 +81,45 @@ public class SecureNio2Channel extends N
             netInBuffer = ByteBuffer.allocate(DEFAULT_NET_BUFFER_SIZE);
             netOutBuffer = ByteBuffer.allocate(DEFAULT_NET_BUFFER_SIZE);
         }
-        handshakeReadCompletionHandler = new CompletionHandler<Integer, 
SocketWrapperBase<Nio2Channel>>() {
-            @Override
-            public void completed(Integer result, 
SocketWrapperBase<Nio2Channel> attachment) {
-                if (result.intValue() < 0) {
-                    failed(new EOFException(), attachment);
-                } else {
-                    endpoint.processSocket(attachment, SocketStatus.OPEN_READ, 
false);
-                }
-            }
-            @Override
-            public void failed(Throwable exc, SocketWrapperBase<Nio2Channel> 
attachment) {
-                endpoint.processSocket(attachment, SocketStatus.ERROR, false);
-            }
-        };
-        handshakeWriteCompletionHandler = new CompletionHandler<Integer, 
SocketWrapperBase<Nio2Channel>>() {
-            @Override
-            public void completed(Integer result, 
SocketWrapperBase<Nio2Channel> attachment) {
-                if (result.intValue() < 0) {
-                    failed(new EOFException(), attachment);
-                } else {
-                    endpoint.processSocket(attachment, 
SocketStatus.OPEN_WRITE, false);
-                }
+        handshakeReadCompletionHandler = new HandshakeReadCompletionHandler();
+        handshakeWriteCompletionHandler = new 
HandshakeWriteCompletionHandler();
+    }
+
+
+    private class HandshakeReadCompletionHandler
+            implements CompletionHandler<Integer, 
SocketWrapperBase<Nio2Channel>> {
+        @Override
+        public void completed(Integer result, SocketWrapperBase<Nio2Channel> 
attachment) {
+            if (result.intValue() < 0) {
+                failed(new EOFException(), attachment);
+            } else {
+                endpoint.processSocket(attachment, SocketStatus.OPEN_READ, 
false);
             }
-            @Override
-            public void failed(Throwable exc, SocketWrapperBase<Nio2Channel> 
attachment) {
-                endpoint.processSocket(attachment, SocketStatus.ERROR, false);
+        }
+        @Override
+        public void failed(Throwable exc, SocketWrapperBase<Nio2Channel> 
attachment) {
+            endpoint.processSocket(attachment, SocketStatus.ERROR, false);
+        }
+    }
+
+
+    private class HandshakeWriteCompletionHandler
+            implements CompletionHandler<Integer, 
SocketWrapperBase<Nio2Channel>> {
+        @Override
+        public void completed(Integer result, SocketWrapperBase<Nio2Channel> 
attachment) {
+            if (result.intValue() < 0) {
+                failed(new EOFException(), attachment);
+            } else {
+                endpoint.processSocket(attachment, SocketStatus.OPEN_WRITE, 
false);
             }
-        };
+        }
+        @Override
+        public void failed(Throwable exc, SocketWrapperBase<Nio2Channel> 
attachment) {
+            endpoint.processSocket(attachment, SocketStatus.ERROR, false);
+        }
     }
 
+
     @Override
     public void reset(AsynchronousSocketChannel channel, 
SocketWrapperBase<Nio2Channel> socket)
             throws IOException {
@@ -187,7 +196,8 @@ public class SecureNio2Channel extends N
      *         close and positive if the handshake is incomplete
      *
      * @throws IOException if an error occurs during the handshake
-     */    @Override
+     */
+    @Override
     public int handshake() throws IOException {
         return handshakeInternal(true);
     }
@@ -468,7 +478,6 @@ public class SecureNio2Channel extends N
      * @throws IOException
      */
     protected SSLEngineResult handshakeUnwrap() throws IOException {
-
         if (netInBuffer.position() == netInBuffer.limit()) {
             //clear the buffer if we have emptied it out on data
             netInBuffer.clear();
@@ -814,7 +823,17 @@ public class SecureNio2Channel extends N
                                 //in the constructor
                                 throw new 
IOException(sm.getString("channel.nio.ssl.unwrapFail", unwrap.getStatus()));
                             }
-                        } while ((netInBuffer.position() != 0)); //continue to 
unwrapping as long as the input buffer has stuff
+                        // continue to unwrap as long as the input buffer has 
stuff
+                        // TODO: unwrap appears only to unwrap one TLS record 
at
+                        //       a time even if there are multiple TLS records
+                        //       in the input buffer. Therefore multiple calls
+                        //       to unwrap are required to ensure that all TLS
+                        //       records are decrypted and written to dst.
+                        //       This may be a bug in tc-native or something
+                        //       that is better handled at that level. For now
+                        //       the '|| unwrap.getStatus() == Status.OK' is a
+                        //       workaround.
+                        } while ((netInBuffer.position() != 0) || 
unwrap.getStatus() == Status.OK);
                         // If everything is OK, so complete
                         handler.completed(Integer.valueOf(read), attach);
                     } catch (Exception e) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to