jdk/src/java.base/share/classes/sun/nio/ch/Net.java
changeset 37676 24ef455da1b0
parent 37593 824750ada3d6
child 37781 71ed5645f17c
equal deleted inserted replaced
37675:a9be5f4baa63 37676:24ef455da1b0
    25 
    25 
    26 package sun.nio.ch;
    26 package sun.nio.ch;
    27 
    27 
    28 import java.io.*;
    28 import java.io.*;
    29 import java.net.*;
    29 import java.net.*;
    30 import jdk.net.*;
       
    31 import java.nio.channels.*;
    30 import java.nio.channels.*;
    32 import java.util.*;
    31 import java.util.*;
    33 import java.security.AccessController;
    32 import java.security.AccessController;
    34 import java.security.PrivilegedAction;
    33 import java.security.PrivilegedAction;
    35 import sun.net.ExtendedOptionsImpl;
    34 import sun.net.ext.ExtendedSocketOptions;
    36 import sun.security.action.GetPropertyAction;
    35 import sun.security.action.GetPropertyAction;
    37 
       
    38 
    36 
    39 public class Net {
    37 public class Net {
    40 
    38 
    41     private Net() { }
    39     private Net() { }
    42 
    40 
   279         throw new AssertionError("Should not reach here");
   277         throw new AssertionError("Should not reach here");
   280     }
   278     }
   281 
   279 
   282     // -- Socket options
   280     // -- Socket options
   283 
   281 
       
   282     static final ExtendedSocketOptions extendedOptions =
       
   283             ExtendedSocketOptions.getInstance();
       
   284 
   284     static void setSocketOption(FileDescriptor fd, ProtocolFamily family,
   285     static void setSocketOption(FileDescriptor fd, ProtocolFamily family,
   285                                 SocketOption<?> name, Object value)
   286                                 SocketOption<?> name, Object value)
   286         throws IOException
   287         throws IOException
   287     {
   288     {
   288         if (value == null)
   289         if (value == null)
   289             throw new IllegalArgumentException("Invalid option value");
   290             throw new IllegalArgumentException("Invalid option value");
   290 
   291 
   291         // only simple values supported by this method
   292         // only simple values supported by this method
   292         Class<?> type = name.type();
   293         Class<?> type = name.type();
   293 
   294 
   294         if (type == SocketFlow.class) {
   295         if (extendedOptions.isOptionSupported(name)) {
   295             SecurityManager sm = System.getSecurityManager();
   296             extendedOptions.setOption(fd, name, value);
   296             if (sm != null) {
       
   297                 sm.checkPermission(new NetworkPermission("setOption.SO_FLOW_SLA"));
       
   298             }
       
   299             ExtendedOptionsImpl.setFlowOption(fd, (SocketFlow)value);
       
   300             return;
   297             return;
   301         }
   298         }
   302 
   299 
   303         if (type != Integer.class && type != Boolean.class)
   300         if (type != Integer.class && type != Boolean.class)
   304             throw new AssertionError("Should not reach here");
   301             throw new AssertionError("Should not reach here");
   351                                   SocketOption<?> name)
   348                                   SocketOption<?> name)
   352         throws IOException
   349         throws IOException
   353     {
   350     {
   354         Class<?> type = name.type();
   351         Class<?> type = name.type();
   355 
   352 
   356         if (type == SocketFlow.class) {
   353         if (extendedOptions.isOptionSupported(name)) {
   357             SecurityManager sm = System.getSecurityManager();
   354             return extendedOptions.getOption(fd, name);
   358             if (sm != null) {
       
   359                 sm.checkPermission(new NetworkPermission("getOption.SO_FLOW_SLA"));
       
   360             }
       
   361             SocketFlow flow = SocketFlow.create();
       
   362             ExtendedOptionsImpl.getFlowOption(fd, flow);
       
   363             return flow;
       
   364         }
   355         }
   365 
   356 
   366         // only simple values supported by this method
   357         // only simple values supported by this method
   367         if (type != Integer.class && type != Boolean.class)
   358         if (type != Integer.class && type != Boolean.class)
   368             throw new AssertionError("Should not reach here");
   359             throw new AssertionError("Should not reach here");