[tomcat] branch master updated: Change PollerEvent to reference the socket wrapper

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch master updated: Change PollerEvent to reference the socket wrapper

remm
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 e024807  Change PollerEvent to reference the socket wrapper
e024807 is described below

commit e02480700374ae8147fb4b9a1d24b96e7fa23041
Author: remm <[hidden email]>
AuthorDate: Fri Nov 20 15:22:14 2020 +0100

    Change PollerEvent to reference the socket wrapper
   
    This forces going through it rather than keep around a NioChannel, and
    is safer.
    Inspired by 45aeed655771308d5185d9dbab8e29a73d87509b
---
 java/org/apache/tomcat/util/net/NioEndpoint.java | 34 +++++++++++-------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 830fba8..2af6dce 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -367,7 +367,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
             socketWrapper.setReadTimeout(getConnectionTimeout());
             socketWrapper.setWriteTimeout(getConnectionTimeout());
             socketWrapper.setKeepAliveLeft(NioEndpoint.this.getMaxKeepAliveRequests());
-            poller.register(channel, socketWrapper);
+            poller.register(socketWrapper);
             return true;
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
@@ -429,20 +429,20 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
      */
     public static class PollerEvent {
 
-        private NioChannel socket;
+        private NioSocketWrapper socketWrapper;
         private int interestOps;
 
-        public PollerEvent(NioChannel ch, int intOps) {
-            reset(ch, intOps);
+        public PollerEvent(NioSocketWrapper socketWrapper, int intOps) {
+            reset(socketWrapper, intOps);
         }
 
-        public void reset(NioChannel ch, int intOps) {
-            socket = ch;
+        public void reset(NioSocketWrapper socketWrapper, int intOps) {
+            this.socketWrapper = socketWrapper;
             interestOps = intOps;
         }
 
-        public NioChannel getSocket() {
-            return socket;
+        public NioSocketWrapper getSocketWrapper() {
+            return socketWrapper;
         }
 
         public int getInterestOps() {
@@ -455,7 +455,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
 
         @Override
         public String toString() {
-            return "Poller event: socket [" + socket + "], socketWrapper [" + socket.getSocketWrapper() +
+            return "Poller event: socket [" + socketWrapper.getSocket() + "], socketWrapper [" + socketWrapper +
                     "], interestOps [" + interestOps + "]";
         }
     }
@@ -519,9 +519,9 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
                 r = eventCache.pop();
             }
             if (r == null) {
-                r = new PollerEvent(socketWrapper.getSocket(), interestOps);
+                r = new PollerEvent(socketWrapper, interestOps);
             } else {
-                r.reset(socketWrapper.getSocket(), interestOps);
+                r.reset(socketWrapper, interestOps);
             }
             addEvent(r);
             if (close) {
@@ -541,9 +541,8 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
             PollerEvent pe = null;
             for (int i = 0, size = events.size(); i < size && (pe = events.poll()) != null; i++ ) {
                 result = true;
-                NioChannel channel = pe.getSocket();
-                SocketChannel sc = channel.getIOChannel();
-                NioSocketWrapper socketWrapper = channel.getSocketWrapper();
+                NioSocketWrapper socketWrapper = pe.getSocketWrapper();
+                SocketChannel sc = socketWrapper.getSocket().getIOChannel();
                 int interestOps = pe.getInterestOps();
                 if (sc == null) {
                     log.warn(sm.getString("endpoint.nio.nullSocketChannel"));
@@ -593,19 +592,18 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
         /**
          * Registers a newly created socket with the poller.
          *
-         * @param socket    The newly created socket
          * @param socketWrapper The socket wrapper
          */
-        public void register(final NioChannel socket, final NioSocketWrapper socketWrapper) {
+        public void register(final NioSocketWrapper socketWrapper) {
             socketWrapper.interestOps(SelectionKey.OP_READ);//this is what OP_REGISTER turns into.
             PollerEvent event = null;
             if (eventCache != null) {
                 event = eventCache.pop();
             }
             if (event == null) {
-                event = new PollerEvent(socket, OP_REGISTER);
+                event = new PollerEvent(socketWrapper, OP_REGISTER);
             } else {
-                event.reset(socket, OP_REGISTER);
+                event.reset(socketWrapper, OP_REGISTER);
             }
             addEvent(event);
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]