jdk/src/share/classes/sun/nio/ch/AsynchronousServerSocketChannelImpl.java
changeset 18192 fa6bd0992104
parent 14342 8435a30053c1
child 18212 22f8c33b0690
equal deleted inserted replaced
18191:be617b8c4427 18192:fa6bd0992104
    61     private volatile boolean open = true;
    61     private volatile boolean open = true;
    62 
    62 
    63     // set true when accept operation is cancelled
    63     // set true when accept operation is cancelled
    64     private volatile boolean acceptKilled;
    64     private volatile boolean acceptKilled;
    65 
    65 
       
    66     // set true when exclusive binding is on and SO_REUSEADDR is emulated
       
    67     private boolean isReuseAddress;
    66 
    68 
    67     AsynchronousServerSocketChannelImpl(AsynchronousChannelGroupImpl group) {
    69     AsynchronousServerSocketChannelImpl(AsynchronousChannelGroupImpl group) {
    68         super(group.provider());
    70         super(group.provider());
    69         this.fd = Net.serverSocket(true);
    71         this.fd = Net.serverSocket(true);
    70     }
    72     }
   184         if (!supportedOptions().contains(name))
   186         if (!supportedOptions().contains(name))
   185             throw new UnsupportedOperationException("'" + name + "' not supported");
   187             throw new UnsupportedOperationException("'" + name + "' not supported");
   186 
   188 
   187         try {
   189         try {
   188             begin();
   190             begin();
   189             Net.setSocketOption(fd, Net.UNSPEC, name, value);
   191             if (name == StandardSocketOptions.SO_REUSEADDR &&
       
   192                     Net.useExclusiveBind())
       
   193             {
       
   194                 // SO_REUSEADDR emulated when using exclusive bind
       
   195                 isReuseAddress = (Boolean)value;
       
   196             } else {
       
   197                 Net.setSocketOption(fd, Net.UNSPEC, name, value);
       
   198             }
   190             return this;
   199             return this;
   191         } finally {
   200         } finally {
   192             end();
   201             end();
   193         }
   202         }
   194     }
   203     }
   201         if (!supportedOptions().contains(name))
   210         if (!supportedOptions().contains(name))
   202             throw new UnsupportedOperationException("'" + name + "' not supported");
   211             throw new UnsupportedOperationException("'" + name + "' not supported");
   203 
   212 
   204         try {
   213         try {
   205             begin();
   214             begin();
       
   215             if (name == StandardSocketOptions.SO_REUSEADDR &&
       
   216                     Net.useExclusiveBind())
       
   217             {
       
   218                 // SO_REUSEADDR emulated when using exclusive bind
       
   219                 return (T)Boolean.valueOf(isReuseAddress);
       
   220             }
   206             return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
   221             return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
   207         } finally {
   222         } finally {
   208             end();
   223             end();
   209         }
   224         }
   210     }
   225     }