jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java
changeset 22340 79163d48aeda
parent 19607 bee007586d06
child 23010 6dadb192ad81
equal deleted inserted replaced
22339:e91bfaf4360d 22340:79163d48aeda
    29 import java.nio.ByteBuffer;
    29 import java.nio.ByteBuffer;
    30 import java.nio.BufferOverflowException;
    30 import java.nio.BufferOverflowException;
    31 import java.net.*;
    31 import java.net.*;
    32 import java.util.concurrent.*;
    32 import java.util.concurrent.*;
    33 import java.io.IOException;
    33 import java.io.IOException;
       
    34 import java.security.AccessController;
       
    35 import java.security.PrivilegedActionException;
       
    36 import java.security.PrivilegedExceptionAction;
    34 import sun.misc.Unsafe;
    37 import sun.misc.Unsafe;
    35 
    38 
    36 /**
    39 /**
    37  * Windows implementation of AsynchronousSocketChannel using overlapped I/O.
    40  * Windows implementation of AsynchronousSocketChannel using overlapped I/O.
    38  */
    41  */
   298             }
   301             }
   299             Invoker.invoke(result);
   302             Invoker.invoke(result);
   300         }
   303         }
   301     }
   304     }
   302 
   305 
       
   306     private void doPrivilegedBind(final SocketAddress sa) throws IOException {
       
   307         try {
       
   308             AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
       
   309                 public Void run() throws IOException {
       
   310                     bind(sa);
       
   311                     return null;
       
   312                 }
       
   313             });
       
   314         } catch (PrivilegedActionException e) {
       
   315             throw (IOException) e.getException();
       
   316         }
       
   317     }
       
   318 
   303     @Override
   319     @Override
   304     <A> Future<Void> implConnect(SocketAddress remote,
   320     <A> Future<Void> implConnect(SocketAddress remote,
   305                                  A attachment,
   321                                  A attachment,
   306                                  CompletionHandler<Void,? super A> handler)
   322                                  CompletionHandler<Void,? super A> handler)
   307     {
   323     {
   328                 throw new AlreadyConnectedException();
   344                 throw new AlreadyConnectedException();
   329             if (state == ST_PENDING)
   345             if (state == ST_PENDING)
   330                 throw new ConnectionPendingException();
   346                 throw new ConnectionPendingException();
   331             if (localAddress == null) {
   347             if (localAddress == null) {
   332                 try {
   348                 try {
   333                     bind(new InetSocketAddress(0));
   349                     SocketAddress any = new InetSocketAddress(0);
       
   350                     if (sm == null) {
       
   351                         bind(any);
       
   352                     } else {
       
   353                         doPrivilegedBind(any);
       
   354                     }
   334                 } catch (IOException x) {
   355                 } catch (IOException x) {
   335                     bindException = x;
   356                     bindException = x;
   336                 }
   357                 }
   337             }
   358             }
   338             if (bindException == null)
   359             if (bindException == null)