< prev index next >

src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java

Print this page




 214     @Override
 215     public <T> SocketChannel setOption(SocketOption<T> name, T value)
 216         throws IOException
 217     {
 218         Objects.requireNonNull(name);
 219         if (!supportedOptions().contains(name))
 220             throw new UnsupportedOperationException("'" + name + "' not supported");
 221 
 222         synchronized (stateLock) {
 223             ensureOpen();
 224 
 225             if (name == StandardSocketOptions.IP_TOS) {
 226                 ProtocolFamily family = Net.isIPv6Available() ?
 227                     StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
 228                 Net.setSocketOption(fd, family, name, value);
 229                 return this;
 230             }
 231 
 232             if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) {
 233                 // SO_REUSEADDR emulated when using exclusive bind


 234                 isReuseAddress = (Boolean)value;
 235                 return this;
 236             }
 237 
 238             // no options that require special handling
 239             Net.setSocketOption(fd, name, value);
 240             return this;
 241         }
 242     }
 243 
 244     @Override
 245     @SuppressWarnings("unchecked")
 246     public <T> T getOption(SocketOption<T> name)
 247         throws IOException
 248     {
 249         Objects.requireNonNull(name);
 250         if (!supportedOptions().contains(name))
 251             throw new UnsupportedOperationException("'" + name + "' not supported");
 252 
 253         synchronized (stateLock) {




 214     @Override
 215     public <T> SocketChannel setOption(SocketOption<T> name, T value)
 216         throws IOException
 217     {
 218         Objects.requireNonNull(name);
 219         if (!supportedOptions().contains(name))
 220             throw new UnsupportedOperationException("'" + name + "' not supported");
 221 
 222         synchronized (stateLock) {
 223             ensureOpen();
 224 
 225             if (name == StandardSocketOptions.IP_TOS) {
 226                 ProtocolFamily family = Net.isIPv6Available() ?
 227                     StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
 228                 Net.setSocketOption(fd, family, name, value);
 229                 return this;
 230             }
 231 
 232             if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) {
 233                 // SO_REUSEADDR emulated when using exclusive bind
 234                 if (!(value instanceof Boolean))
 235                     throw new IllegalArgumentException("Invalid value '" + value + "'");
 236                 isReuseAddress = (Boolean)value;
 237                 return this;
 238             }
 239 
 240             // no options that require special handling
 241             Net.setSocketOption(fd, name, value);
 242             return this;
 243         }
 244     }
 245 
 246     @Override
 247     @SuppressWarnings("unchecked")
 248     public <T> T getOption(SocketOption<T> name)
 249         throws IOException
 250     {
 251         Objects.requireNonNull(name);
 252         if (!supportedOptions().contains(name))
 253             throw new UnsupportedOperationException("'" + name + "' not supported");
 254 
 255         synchronized (stateLock) {


< prev index next >