You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2019/10/02 15:53:38 UTC

[tomcat] branch master updated: Minor NIO refactoring to align with NIO2

This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 2e47b58  Minor NIO refactoring to align with NIO2
2e47b58 is described below

commit 2e47b58fb3667f56a5d7332ffb6fd3c7ce13b8a0
Author: remm <re...@apache.org>
AuthorDate: Wed Oct 2 17:53:25 2019 +0200

    Minor NIO refactoring to align with NIO2
    
    NIO2 uses the reset() method instead of setter in a weird order, this
    looks better to me.
---
 java/org/apache/tomcat/util/net/NioChannel.java    | 28 +++++++---------------
 java/org/apache/tomcat/util/net/NioEndpoint.java   |  6 ++---
 .../apache/tomcat/util/net/SecureNioChannel.java   |  7 +++---
 3 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/NioChannel.java b/java/org/apache/tomcat/util/net/NioChannel.java
index 9f39afb..75bc3f8 100644
--- a/java/org/apache/tomcat/util/net/NioChannel.java
+++ b/java/org/apache/tomcat/util/net/NioChannel.java
@@ -44,23 +44,21 @@ public class NioChannel implements ByteChannel, ScatteringByteChannel, Gathering
     protected SocketChannel sc = null;
     protected NioSocketWrapper socketWrapper = null;
 
-    public NioChannel(SocketChannel channel, SocketBufferHandler bufHandler) {
-        this.sc = channel;
+    public NioChannel(SocketBufferHandler bufHandler) {
         this.bufHandler = bufHandler;
     }
 
     /**
      * Reset the channel
      *
+     * @param channel the socket channel
+     * @param socketWrapper the socket wrapper
      * @throws IOException If a problem was encountered resetting the channel
      */
-    public void reset() throws IOException {
-        bufHandler.reset();
-    }
-
-
-    void setSocketWrapper(NioSocketWrapper socketWrapper) {
+    public void reset(SocketChannel channel, NioSocketWrapper socketWrapper) throws IOException {
+        this.sc = channel;
         this.socketWrapper = socketWrapper;
+        bufHandler.reset();
     }
 
     /**
@@ -205,10 +203,6 @@ public class NioChannel implements ByteChannel, ScatteringByteChannel, Gathering
         return 0;
     }
 
-    public void setIOChannel(SocketChannel sc) {
-        this.sc = sc;
-    }
-
     @Override
     public String toString() {
         return super.toString() + ":" + sc.toString();
@@ -257,7 +251,7 @@ public class NioChannel implements ByteChannel, ScatteringByteChannel, Gathering
     static final NioChannel CLOSED_NIO_CHANNEL = new ClosedNioChannel();
     public static class ClosedNioChannel extends NioChannel {
         public ClosedNioChannel() {
-            super(null, SocketBufferHandler.EMPTY);
+            super(SocketBufferHandler.EMPTY);
         }
         @Override
         public void close() throws IOException {
@@ -267,18 +261,12 @@ public class NioChannel implements ByteChannel, ScatteringByteChannel, Gathering
             return false;
         }
         @Override
-        public void reset() throws IOException {
+        public void reset(SocketChannel channel, NioSocketWrapper socketWrapper) throws IOException {
         }
         @Override
         public void free() {
         }
         @Override
-        void setSocketWrapper(NioSocketWrapper socketWrapper) {
-        }
-        @Override
-        public void setIOChannel(SocketChannel sc) {
-        }
-        @Override
         public void setAppReadBufHandler(ApplicationBufferHandler handler) {
         }
         @Override
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 78a74f0..99d8896 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -412,14 +412,12 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
                 if (isSSLEnabled()) {
                     channel = new SecureNioChannel(socket, bufhandler, selectorPool, this);
                 } else {
-                    channel = new NioChannel(socket, bufhandler);
+                    channel = new NioChannel(bufhandler);
                 }
             } else {
-                channel.setIOChannel(socket);
-                channel.reset();
             }
             NioSocketWrapper socketWrapper = new NioSocketWrapper(channel, this);
-            channel.setSocketWrapper(socketWrapper);
+            channel.reset(socket, socketWrapper);
             socketWrapper.setReadTimeout(getConnectionTimeout());
             socketWrapper.setWriteTimeout(getConnectionTimeout());
             socketWrapper.setKeepAliveLeft(NioEndpoint.this.getMaxKeepAliveRequests());
diff --git a/java/org/apache/tomcat/util/net/SecureNioChannel.java b/java/org/apache/tomcat/util/net/SecureNioChannel.java
index 5dc2fe5..4c4c85a 100644
--- a/java/org/apache/tomcat/util/net/SecureNioChannel.java
+++ b/java/org/apache/tomcat/util/net/SecureNioChannel.java
@@ -36,6 +36,7 @@ import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.buf.ByteBufferUtils;
 import org.apache.tomcat.util.compat.JreCompat;
+import org.apache.tomcat.util.net.NioEndpoint.NioSocketWrapper;
 import org.apache.tomcat.util.net.TLSClientHelloExtractor.ExtractorResult;
 import org.apache.tomcat.util.net.openssl.ciphers.Cipher;
 import org.apache.tomcat.util.res.StringManager;
@@ -71,7 +72,7 @@ public class SecureNioChannel extends NioChannel {
 
     public SecureNioChannel(SocketChannel channel, SocketBufferHandler bufHandler,
             NioSelectorPool pool, NioEndpoint endpoint) {
-        super(channel, bufHandler);
+        super(bufHandler);
 
         // Create the network buffers (these hold the encrypted data).
         if (endpoint.getSocketProperties().getDirectSslBuffer()) {
@@ -88,8 +89,8 @@ public class SecureNioChannel extends NioChannel {
     }
 
     @Override
-    public void reset() throws IOException {
-        super.reset();
+    public void reset(SocketChannel channel, NioSocketWrapper socketWrapper) throws IOException {
+        super.reset(channel, socketWrapper);
         sslEngine = null;
         sniComplete = false;
         handshakeComplete = false;


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