[PATCH mptcp-next 2/7] Add MPTCP server socket creation support

Geliang Tang posted 7 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH mptcp-next 2/7] Add MPTCP server socket creation support
Posted by Geliang Tang 1 month, 3 weeks ago
This patch introduces new methods to create server sockets with Multipath
TCP (MPTCP) support:

1. Added an overloaded 'serverSocket' method that accepts an 'mptcp'
   parameter to enable MPTCP
2. Added a convenience method 'mptcpServerSocket()' for creating
   MPTCP-enabled server sockets using the unspecified protocol family by
   default

The changes maintain backward compatibility while providing explicit MPTCP
support for server socket creation. The new methods leverage the existing
socket0 infrastructure with the MPTCP flag added in the previous patch.

Co-Developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <geliang@kernel.org>
---
 src/java.base/share/classes/sun/nio/ch/Net.java | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/java.base/share/classes/sun/nio/ch/Net.java b/src/java.base/share/classes/sun/nio/ch/Net.java
index c086429380b..aa3ed087d2c 100644
--- a/src/java.base/share/classes/sun/nio/ch/Net.java
+++ b/src/java.base/share/classes/sun/nio/ch/Net.java
@@ -501,6 +501,16 @@ static FileDescriptor serverSocket(ProtocolFamily family) {
         return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false));
     }
 
+    static FileDescriptor serverSocket(ProtocolFamily family, boolean mptcp) {
+        boolean preferIPv6 = isIPv6Available() &&
+            (family != StandardProtocolFamily.INET);
+        return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, mptcp));
+    }
+
+    static FileDescriptor mptcpServerSocket() {
+        return serverSocket(UNSPEC, true);
+    }
+
     // Due to oddities SO_REUSEADDR on Windows reuse is ignored
     private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse,
                                       boolean fastLoopback, boolean mptcp);
-- 
2.48.1
Re: [PATCH mptcp-next 2/7] Add MPTCP server socket creation support
Posted by Matthieu Baerts 1 month, 2 weeks ago
Hi Geliang,

On 23/07/2025 07:16, Geliang Tang wrote:
> This patch introduces new methods to create server sockets with Multipath
> TCP (MPTCP) support:
> 
> 1. Added an overloaded 'serverSocket' method that accepts an 'mptcp'
>    parameter to enable MPTCP
> 2. Added a convenience method 'mptcpServerSocket()' for creating
>    MPTCP-enabled server sockets using the unspecified protocol family by
>    default
> 
> The changes maintain backward compatibility while providing explicit MPTCP
> support for server socket creation. The new methods leverage the existing
> socket0 infrastructure with the MPTCP flag added in the previous patch.
> 
> Co-Developed-by: Gang Yan <yangang@kylinos.cn>
> Signed-off-by: Gang Yan <yangang@kylinos.cn>
> Signed-off-by: Geliang Tang <geliang@kernel.org>
> ---
>  src/java.base/share/classes/sun/nio/ch/Net.java | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/src/java.base/share/classes/sun/nio/ch/Net.java b/src/java.base/share/classes/sun/nio/ch/Net.java
> index c086429380b..aa3ed087d2c 100644
> --- a/src/java.base/share/classes/sun/nio/ch/Net.java
> +++ b/src/java.base/share/classes/sun/nio/ch/Net.java
> @@ -501,6 +501,16 @@ static FileDescriptor serverSocket(ProtocolFamily family) {
>          return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false));
>      }
>  
> +    static FileDescriptor serverSocket(ProtocolFamily family, boolean mptcp) {
> +        boolean preferIPv6 = isIPv6Available() &&
> +            (family != StandardProtocolFamily.INET);
> +        return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, mptcp));
> +    }
> +
> +    static FileDescriptor mptcpServerSocket() {

I didn't check what is usually being done, but is this new helper really
needed? Is it not enough with the new serverSocket() extension?

Also, could you not have serverSocket(ProtocolFamily family) calling the
new serverSocket(family, false) instead of duplicating the code above?

> +        return serverSocket(UNSPEC, true);
> +    }
> +
>      // Due to oddities SO_REUSEADDR on Windows reuse is ignored
>      private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse,
>                                        boolean fastLoopback, boolean mptcp);

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.