src/jdk.net/share/classes/jdk/net/Sockets.java

Print this page
rev 14282 : 8044773: Refactor jdk.net API so that it can be moved out of the base module
Reviewed-by:

@@ -25,19 +25,16 @@
 
 package jdk.net;
 
 import java.net.*;
 import java.io.IOException;
-import java.io.FileDescriptor;
-import java.security.PrivilegedAction;
-import java.security.AccessController;
-import java.lang.reflect.Field;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.HashMap;
 import java.util.Collections;
-import sun.net.ExtendedOptionsImpl;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import jdk.net.ExtendedSocketOptions.PlatformSocketOptions;
 
 /**
  * Defines static methods to set and get socket options defined by the
  * {@link java.net.SocketOption} interface. All of the standard options defined
  * by {@link java.net.Socket}, {@link java.net.ServerSocket}, and

@@ -55,16 +52,12 @@
  *
  * @see java.nio.channels.NetworkChannel
  */
 public class Sockets {
 
-    private static final HashMap<Class<?>,Set<SocketOption<?>>>
-        options = new HashMap<>();
-
-    static {
-        initOptionSets();
-    }
+    private static final Map<Class<?>,Set<SocketOption<?>>>
+            options = optionSets();
 
     private Sockets() {}
 
     /**
      * Sets the value of a socket option on a {@link java.net.Socket}

@@ -257,18 +250,20 @@
     /**
      * Tells whether SO_REUSEPORT is supported.
      */
     static boolean isReusePortAvailable() {
         if (!checkedReusePort) {
-            isReusePortAvailable = isReusePortAvailable0();
+            Set<SocketOption<?>> s = new Socket().supportedOptions();
+            isReusePortAvailable = s.contains(StandardSocketOptions.SO_REUSEPORT);
             checkedReusePort = true;
         }
         return isReusePortAvailable;
     }
 
-    private static void initOptionSets() {
-        boolean flowsupported = ExtendedOptionsImpl.flowSupported();
+    private static Map<Class<?>,Set<SocketOption<?>>> optionSets() {
+        Map<Class<?>,Set<SocketOption<?>>> options = new HashMap<>();
+        boolean flowsupported = PlatformSocketOptions.get().flowSupported();
         boolean reuseportsupported = isReusePortAvailable();
         // Socket
 
         Set<SocketOption<?>> set = new HashSet<>();
         set.add(StandardSocketOptions.SO_KEEPALIVE);

@@ -331,9 +326,9 @@
         if (flowsupported) {
             set.add(ExtendedSocketOptions.SO_FLOW_SLA);
         }
         set = Collections.unmodifiableSet(set);
         options.put(MulticastSocket.class, set);
-    }
 
-    private static native boolean isReusePortAvailable0();
+        return Collections.unmodifiableMap(options);
+    }
 }