jdk/src/java.base/unix/classes/java/net/PlainSocketImpl.java
changeset 36115 0676e37a0b9c
parent 34968 93b315c61ca3
child 37676 24ef455da1b0
equal deleted inserted replaced
36114:a5ed9456c9be 36115:0676e37a0b9c
     1 /*
     1 /*
     2  * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    57         this.fd = fd;
    57         this.fd = fd;
    58     }
    58     }
    59 
    59 
    60     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
    60     protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
    61         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
    61         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
    62             super.setOption(name, value);
    62             if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
       
    63                 super.setOption(name, value);
       
    64             } else {
       
    65                 if (supportedOptions().contains(name)) {
       
    66                     super.setOption(name, value);
       
    67                 } else {
       
    68                     throw new UnsupportedOperationException("unsupported option");
       
    69                 }
       
    70             }
    63         } else {
    71         } else {
    64             if (getSocket() == null || !flowSupported()) {
    72             if (getSocket() == null || !flowSupported()) {
    65                 throw new UnsupportedOperationException("unsupported option");
    73                 throw new UnsupportedOperationException("unsupported option");
    66             }
    74             }
    67             if (isClosedOrPending()) {
    75             if (isClosedOrPending()) {
    74     }
    82     }
    75 
    83 
    76     @SuppressWarnings("unchecked")
    84     @SuppressWarnings("unchecked")
    77     protected <T> T getOption(SocketOption<T> name) throws IOException {
    85     protected <T> T getOption(SocketOption<T> name) throws IOException {
    78         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
    86         if (!name.equals(ExtendedSocketOptions.SO_FLOW_SLA)) {
    79             return super.getOption(name);
    87             if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
       
    88                 return super.getOption(name);
       
    89             } else {
       
    90                 if (supportedOptions().contains(name)) {
       
    91                     return super.getOption(name);
       
    92                 } else {
       
    93                     throw new UnsupportedOperationException("unsupported option");
       
    94                 }
       
    95             }
    80         }
    96         }
    81         if (getSocket() == null || !flowSupported()) {
    97         if (getSocket() == null || !flowSupported()) {
    82             throw new UnsupportedOperationException("unsupported option");
    98             throw new UnsupportedOperationException("unsupported option");
    83         }
    99         }
    84         if (isClosedOrPending()) {
   100         if (isClosedOrPending()) {
    99         }
   115         }
   100         return options;
   116         return options;
   101     }
   117     }
   102 
   118 
   103     protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
   119     protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
       
   120         if (opt == SocketOptions.SO_REUSEPORT && !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {
       
   121             throw new UnsupportedOperationException("unsupported option");
       
   122         }
   104         try {
   123         try {
   105             socketSetOption0(opt, b, val);
   124             socketSetOption0(opt, b, val);
   106         } catch (SocketException se) {
   125         } catch (SocketException se) {
   107             if (socket == null || !socket.isConnected())
   126             if (socket == null || !socket.isConnected())
   108                 throw se;
   127                 throw se;