[PATCH mptcp-next 4/7] Add MPTCP support to NioSocketImpl

Geliang Tang posted 7 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH mptcp-next 4/7] Add MPTCP support to NioSocketImpl
Posted by Geliang Tang 1 month, 3 weeks ago
This patch integrates MPTCP support into the core socket implementation
by:

1. Adding a new createPlatformSocketImpl factory method that accepts an
   mptcp parameter
2. Extending NioSocketImpl to track MPTCP state with a new mptcp field
3. Modifying socket creation logic to use the appropriate MPTCP-enabled
   methods:
   - Uses Net.mptcpServerSocket() for server sockets when MPTCP is enabled
   - Uses Net.mptcpSocket() for client sockets when MPTCP is enabled

The changes maintain backward compatibility while adding first-class MPTCP
support to the socket implementation layer. The implementation builds upon
the MPTCP infrastructure added in previous patches.

Co-Developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <geliang@kernel.org>
---
 .../share/classes/java/net/SocketImpl.java    |  8 ++++++++
 .../classes/sun/nio/ch/NioSocketImpl.java     | 19 +++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/java.base/share/classes/java/net/SocketImpl.java b/src/java.base/share/classes/java/net/SocketImpl.java
index 15c12457aac..9d07366350c 100644
--- a/src/java.base/share/classes/java/net/SocketImpl.java
+++ b/src/java.base/share/classes/java/net/SocketImpl.java
@@ -52,6 +52,14 @@ static <S extends SocketImpl & PlatformSocketImpl> S createPlatformSocketImpl(bo
         return (S) new NioSocketImpl(server);
     }
 
+    /**
+     * Creates an instance of platform's SocketImpl
+     */
+    @SuppressWarnings("unchecked")
+    static <S extends SocketImpl & PlatformSocketImpl> S createPlatformSocketImpl(boolean server, boolean mptcp) {
+        return (S) new NioSocketImpl(server, mptcp);
+    }
+
     /**
      * The file descriptor object for this socket.
      */
diff --git a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java
index dd81b356738..cf95a4e466e 100644
--- a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java
+++ b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java
@@ -86,6 +86,9 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
     // true if this is a SocketImpl for a ServerSocket
     private final boolean server;
 
+    // true if this is a SocketImpl for a MptcpServerSocket
+    private final boolean mptcp;
+
     // Lock held when reading (also used when accepting or connecting)
     private final ReentrantLock readLock = new ReentrantLock();
 
@@ -131,6 +134,18 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
      */
     public NioSocketImpl(boolean server) {
         this.server = server;
+        this.mptcp = false;
+    }
+
+    /**
+     * @param mptcp enable MPTCP
+     *
+     * Creates an instance of this SocketImpl.
+     * @param server true if this is a SocketImpl for a ServerSocket
+     */
+    public NioSocketImpl(boolean server, boolean mptcp) {
+        this.server = server;
+        this.mptcp = mptcp;
     }
 
     /**
@@ -468,9 +483,9 @@ protected void create(boolean stream) throws IOException {
                 throw new IOException("Already created");
             FileDescriptor fd;
             if (server) {
-                fd = Net.serverSocket();
+                fd = mptcp ? Net.mptcpServerSocket() : Net.serverSocket();
             } else {
-                fd = Net.socket();
+                fd = mptcp ? Net.mptcpSocket() : Net.socket();
             }
             Runnable closer = closerFor(fd);
             this.fd = fd;
-- 
2.48.1