src/share/classes/sun/nio/ch/Net.java

Print this page
rev 7398 : 8032808: Support Solaris SO_FLOW_SLA socket option
Reviewed-by: michaelm
rev 7400 : 8029607: Type of Service (TOS) cannot be set in IPv6 header
Reviewed-by: alanb

@@ -25,15 +25,17 @@
 
 package sun.nio.ch;
 
 import java.io.*;
 import java.net.*;
+import jdk.net.*;
 import java.nio.channels.*;
 import java.util.*;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
+import sun.net.ExtendedOptionsImpl;
 
 
 class Net {                                             // package-private
 
     private Net() { }

@@ -325,10 +327,20 @@
         if (value == null)
             throw new IllegalArgumentException("Invalid option value");
 
         // only simple values supported by this method
         Class<?> type = name.type();
+
+        if (type == SocketFlow.class) {
+            SecurityManager sm = System.getSecurityManager();
+            if (sm != null) {
+                sm.checkPermission(new NetworkPermission("setOption.SO_FLOW_SLA"));
+            }
+            ExtendedOptionsImpl.setFlowOption(fd, (SocketFlow)value);
+            return;
+        }
+
         if (type != Integer.class && type != Boolean.class)
             throw new AssertionError("Should not reach here");
 
         // special handling
         if (name == StandardSocketOptions.SO_RCVBUF ||

@@ -368,19 +380,30 @@
             boolean b = ((Boolean)value).booleanValue();
             arg = (b) ? 1 : 0;
         }
 
         boolean mayNeedConversion = (family == UNSPEC);
-        setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg);
+        boolean isIPv6 = (family == StandardProtocolFamily.INET6);
+        setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg, isIPv6);
     }
 
     static Object getSocketOption(FileDescriptor fd, ProtocolFamily family,
                                   SocketOption<?> name)
         throws IOException
     {
         Class<?> type = name.type();
 
+        if (type == SocketFlow.class) {
+            SecurityManager sm = System.getSecurityManager();
+            if (sm != null) {
+                sm.checkPermission(new NetworkPermission("getOption.SO_FLOW_SLA"));
+            }
+            SocketFlow flow = SocketFlow.create();
+            ExtendedOptionsImpl.getFlowOption(fd, flow);
+            return flow;
+        }
+
         // only simple values supported by this method
         if (type != Integer.class && type != Boolean.class)
             throw new AssertionError("Should not reach here");
 
         // map option name to platform level/name

@@ -505,11 +528,11 @@
     private static native int getIntOption0(FileDescriptor fd, boolean mayNeedConversion,
                                             int level, int opt)
         throws IOException;
 
     private static native void setIntOption0(FileDescriptor fd, boolean mayNeedConversion,
-                                             int level, int opt, int arg)
+                                             int level, int opt, int arg, boolean isIPv6)
         throws IOException;
 
     // -- Multicast support --