src/java.base/unix/classes/java/net/PlainSocketImpl.java
changeset 55081 dd321e3596c0
parent 54689 b28b7f631301
equal deleted inserted replaced
55080:ef713640430e 55081:dd321e3596c0
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package java.net;
    25 package java.net;
    26 
    26 
    27 import java.io.IOException;
    27 import java.io.IOException;
    28 import java.io.FileDescriptor;
       
    29 import java.util.Set;
    28 import java.util.Set;
    30 import java.util.HashSet;
    29 import java.util.HashSet;
    31 import sun.net.ext.ExtendedSocketOptions;
    30 import sun.net.ext.ExtendedSocketOptions;
    32 
    31 
    33 /*
    32 /*
    45     /**
    44     /**
    46      * Constructs an empty instance.
    45      * Constructs an empty instance.
    47      */
    46      */
    48     PlainSocketImpl(boolean isServer) {
    47     PlainSocketImpl(boolean isServer) {
    49         super(isServer);
    48         super(isServer);
    50     }
       
    51 
       
    52     static final ExtendedSocketOptions extendedOptions =
       
    53             ExtendedSocketOptions.getInstance();
       
    54 
       
    55     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
       
    56         if (isClosedOrPending()) {
       
    57             throw new SocketException("Socket closed");
       
    58         }
       
    59         if (supportedOptions().contains(name)) {
       
    60             if (extendedOptions.isOptionSupported(name)) {
       
    61                 extendedOptions.setOption(fd, name, value);
       
    62             } else {
       
    63                 super.setOption(name, value);
       
    64             }
       
    65         } else {
       
    66             throw new UnsupportedOperationException("unsupported option");
       
    67         }
       
    68     }
       
    69 
       
    70     @SuppressWarnings("unchecked")
       
    71     protected <T> T getOption(SocketOption<T> name) throws IOException {
       
    72         if (isClosedOrPending()) {
       
    73             throw new SocketException("Socket closed");
       
    74         }
       
    75         if (supportedOptions().contains(name)) {
       
    76             if (extendedOptions.isOptionSupported(name)) {
       
    77                 return (T) extendedOptions.getOption(fd, name);
       
    78             } else {
       
    79                 return super.getOption(name);
       
    80             }
       
    81         } else {
       
    82             throw new UnsupportedOperationException("unsupported option");
       
    83         }
       
    84     }
       
    85 
       
    86     protected Set<SocketOption<?>> supportedOptions() {
       
    87         HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions());
       
    88         if (isServer) {
       
    89             options.addAll(ExtendedSocketOptions.serverSocketOptions());
       
    90         } else {
       
    91             options.addAll(ExtendedSocketOptions.clientSocketOptions());
       
    92         }
       
    93         return options;
       
    94     }
    49     }
    95 
    50 
    96     protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
    51     protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
    97         if (opt == SocketOptions.SO_REUSEPORT &&
    52         if (opt == SocketOptions.SO_REUSEPORT &&
    98             !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {
    53             !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {