< prev index next >

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

Print this page




 130         }
 131     }
 132 
 133     @Override
 134     public SocketAddress getLocalAddress() throws IOException {
 135         synchronized (stateLock) {
 136             ensureOpen();
 137             return (localAddress == null)
 138                     ? null
 139                     : Net.getRevealedLocalAddress(localAddress);
 140         }
 141     }
 142 
 143     @Override
 144     public <T> ServerSocketChannel setOption(SocketOption<T> name, T value)
 145         throws IOException
 146     {
 147         Objects.requireNonNull(name);
 148         if (!supportedOptions().contains(name))
 149             throw new UnsupportedOperationException("'" + name + "' not supported");

 150         synchronized (stateLock) {
 151             ensureOpen();
 152 
 153             if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) {
 154                 // SO_REUSEADDR emulated when using exclusive bind


 155                 isReuseAddress = (Boolean)value;
 156             } else {
 157                 // no options that require special handling
 158                 Net.setSocketOption(fd, Net.UNSPEC, name, value);
 159             }
 160             return this;
 161         }
 162     }
 163 
 164     @Override
 165     @SuppressWarnings("unchecked")
 166     public <T> T getOption(SocketOption<T> name)
 167         throws IOException
 168     {
 169         Objects.requireNonNull(name);
 170         if (!supportedOptions().contains(name))
 171             throw new UnsupportedOperationException("'" + name + "' not supported");
 172 
 173         synchronized (stateLock) {
 174             ensureOpen();




 130         }
 131     }
 132 
 133     @Override
 134     public SocketAddress getLocalAddress() throws IOException {
 135         synchronized (stateLock) {
 136             ensureOpen();
 137             return (localAddress == null)
 138                     ? null
 139                     : Net.getRevealedLocalAddress(localAddress);
 140         }
 141     }
 142 
 143     @Override
 144     public <T> ServerSocketChannel setOption(SocketOption<T> name, T value)
 145         throws IOException
 146     {
 147         Objects.requireNonNull(name);
 148         if (!supportedOptions().contains(name))
 149             throw new UnsupportedOperationException("'" + name + "' not supported");
 150 
 151         synchronized (stateLock) {
 152             ensureOpen();
 153 
 154             if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) {
 155                 // SO_REUSEADDR emulated when using exclusive bind
 156                 if (!(value instanceof Boolean))
 157                     throw new IllegalArgumentException("Invalid value '" + value + "'");
 158                 isReuseAddress = (Boolean)value;
 159             } else {
 160                 // no options that require special handling
 161                 Net.setSocketOption(fd, Net.UNSPEC, name, value);
 162             }
 163             return this;
 164         }
 165     }
 166 
 167     @Override
 168     @SuppressWarnings("unchecked")
 169     public <T> T getOption(SocketOption<T> name)
 170         throws IOException
 171     {
 172         Objects.requireNonNull(name);
 173         if (!supportedOptions().contains(name))
 174             throw new UnsupportedOperationException("'" + name + "' not supported");
 175 
 176         synchronized (stateLock) {
 177             ensureOpen();


< prev index next >