jdk/src/share/classes/sun/nio/ch/AsynchronousSocketChannelImpl.java
changeset 18192 fa6bd0992104
parent 14342 8435a30053c1
child 18212 22f8c33b0690
equal deleted inserted replaced
18191:be617b8c4427 18192:fa6bd0992104
    77 
    77 
    78     // close support
    78     // close support
    79     private final ReadWriteLock closeLock = new ReentrantReadWriteLock();
    79     private final ReadWriteLock closeLock = new ReentrantReadWriteLock();
    80     private volatile boolean open = true;
    80     private volatile boolean open = true;
    81 
    81 
       
    82     // set true when exclusive binding is on and SO_REUSEADDR is emulated
       
    83     private boolean isReuseAddress;
       
    84 
    82     AsynchronousSocketChannelImpl(AsynchronousChannelGroupImpl group)
    85     AsynchronousSocketChannelImpl(AsynchronousChannelGroupImpl group)
    83         throws IOException
    86         throws IOException
    84     {
    87     {
    85         super(group.provider());
    88         super(group.provider());
    86         this.fd = Net.socket(true);
    89         this.fd = Net.socket(true);
   453 
   456 
   454         try {
   457         try {
   455             begin();
   458             begin();
   456             if (writeShutdown)
   459             if (writeShutdown)
   457                 throw new IOException("Connection has been shutdown for writing");
   460                 throw new IOException("Connection has been shutdown for writing");
   458             Net.setSocketOption(fd, Net.UNSPEC, name, value);
   461             if (name == StandardSocketOptions.SO_REUSEADDR &&
       
   462                     Net.useExclusiveBind())
       
   463             {
       
   464                 // SO_REUSEADDR emulated when using exclusive bind
       
   465                 isReuseAddress = (Boolean)value;
       
   466             } else {
       
   467                 Net.setSocketOption(fd, Net.UNSPEC, name, value);
       
   468             }
   459             return this;
   469             return this;
   460         } finally {
   470         } finally {
   461             end();
   471             end();
   462         }
   472         }
   463     }
   473     }
   470         if (!supportedOptions().contains(name))
   480         if (!supportedOptions().contains(name))
   471             throw new UnsupportedOperationException("'" + name + "' not supported");
   481             throw new UnsupportedOperationException("'" + name + "' not supported");
   472 
   482 
   473         try {
   483         try {
   474             begin();
   484             begin();
       
   485             if (name == StandardSocketOptions.SO_REUSEADDR &&
       
   486                     Net.useExclusiveBind())
       
   487             {
       
   488                 // SO_REUSEADDR emulated when using exclusive bind
       
   489                 return (T)Boolean.valueOf(isReuseAddress);
       
   490             }
   475             return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
   491             return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
   476         } finally {
   492         } finally {
   477             end();
   493             end();
   478         }
   494         }
   479     }
   495     }