jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java
changeset 25170 f58832169add
parent 24969 afa6934dd8e8
equal deleted inserted replaced
25169:365cba5326f9 25170:f58832169add
   171 
   171 
   172         synchronized (stateLock) {
   172         synchronized (stateLock) {
   173             if (!isOpen())
   173             if (!isOpen())
   174                 throw new ClosedChannelException();
   174                 throw new ClosedChannelException();
   175 
   175 
   176             // special handling for IP_TOS: no-op when IPv6
       
   177             if (name == StandardSocketOptions.IP_TOS) {
   176             if (name == StandardSocketOptions.IP_TOS) {
   178                 if (!Net.isIPv6Available())
   177                 ProtocolFamily family = Net.isIPv6Available() ?
   179                     Net.setSocketOption(fd, StandardProtocolFamily.INET, name, value);
   178                     StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
       
   179                 Net.setSocketOption(fd, family, name, value);
   180                 return this;
   180                 return this;
   181             } else if (name == StandardSocketOptions.SO_REUSEADDR &&
   181             }
   182                            Net.useExclusiveBind())
   182 
   183             {
   183             if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) {
   184                 // SO_REUSEADDR emulated when using exclusive bind
   184                 // SO_REUSEADDR emulated when using exclusive bind
   185                 isReuseAddress = (Boolean)value;
   185                 isReuseAddress = (Boolean)value;
   186                 return this;
   186                 return this;
   187             }
   187             }
   188 
   188 
   213                 return (T)Boolean.valueOf(isReuseAddress);
   213                 return (T)Boolean.valueOf(isReuseAddress);
   214             }
   214             }
   215 
   215 
   216             // special handling for IP_TOS: always return 0 when IPv6
   216             // special handling for IP_TOS: always return 0 when IPv6
   217             if (name == StandardSocketOptions.IP_TOS) {
   217             if (name == StandardSocketOptions.IP_TOS) {
   218                 return (Net.isIPv6Available()) ? (T) Integer.valueOf(0) :
   218                 ProtocolFamily family = Net.isIPv6Available() ?
   219                     (T) Net.getSocketOption(fd, StandardProtocolFamily.INET, name);
   219                     StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
       
   220                 return (T) Net.getSocketOption(fd, family, name);
   220             }
   221             }
   221 
   222 
   222             // no options that require special handling
   223             // no options that require special handling
   223             return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
   224             return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
   224         }
   225         }