< prev index next >

src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java

Print this page




 199      * the given file descriptor and remote address. If this method completes
 200      * with an IOException or SecurityException then the channel/file descriptor
 201      * will be closed.
 202      */
 203     private AsynchronousSocketChannel finishAccept(FileDescriptor newfd,
 204                                                    final InetSocketAddress remote,
 205                                                    AccessControlContext acc)
 206         throws IOException, SecurityException
 207     {
 208         AsynchronousSocketChannel ch = null;
 209         try {
 210             ch = new UnixAsynchronousSocketChannelImpl(port, newfd, remote);
 211         } catch (IOException x) {
 212             nd.close(newfd);
 213             throw x;
 214         }
 215 
 216         // permission check must always be in initiator's context
 217         try {
 218             if (acc != null) {
 219                 AccessController.doPrivileged(new PrivilegedAction<Void>() {
 220                     public Void run() {
 221                         SecurityManager sm = System.getSecurityManager();
 222                         if (sm != null) {
 223                             sm.checkAccept(remote.getAddress().getHostAddress(),
 224                                            remote.getPort());
 225                         }
 226                         return null;
 227                     }
 228                 }, acc);
 229             } else {
 230                 SecurityManager sm = System.getSecurityManager();
 231                 if (sm != null) {
 232                     sm.checkAccept(remote.getAddress().getHostAddress(),
 233                                    remote.getPort());
 234                 }
 235             }
 236         } catch (SecurityException x) {
 237             try {
 238                 ch.close();
 239             } catch (Throwable suppressed) {


 270         if (!accepting.compareAndSet(false, true))
 271             throw new AcceptPendingException();
 272 
 273         // attempt accept
 274         FileDescriptor newfd = new FileDescriptor();
 275         InetSocketAddress[] isaa = new InetSocketAddress[1];
 276         Throwable exc = null;
 277         try {
 278             begin();
 279 
 280             int n = accept(this.fd, newfd, isaa);
 281             if (n == IOStatus.UNAVAILABLE) {
 282 
 283                 // need calling context when there is security manager as
 284                 // permission check may be done in a different thread without
 285                 // any application call frames on the stack
 286                 PendingFuture<AsynchronousSocketChannel,Object> result = null;
 287                 synchronized (updateLock) {
 288                     if (handler == null) {
 289                         this.acceptHandler = null;
 290                         result = new PendingFuture<AsynchronousSocketChannel,Object>(this);
 291                         this.acceptFuture = result;
 292                     } else {
 293                         this.acceptHandler = handler;
 294                         this.acceptAttachment = att;
 295                     }
 296                     this.acceptAcc = (System.getSecurityManager() == null) ?
 297                         null : AccessController.getContext();
 298                     this.acceptPending = true;
 299                 }
 300 
 301                 // register for connections
 302                 port.startPoll(fdVal, Net.POLLIN);
 303                 return result;
 304             }
 305         } catch (Throwable x) {
 306             // accept failed
 307             if (x instanceof ClosedChannelException)
 308                 x = new AsynchronousCloseException();
 309             exc = x;
 310         } finally {




 199      * the given file descriptor and remote address. If this method completes
 200      * with an IOException or SecurityException then the channel/file descriptor
 201      * will be closed.
 202      */
 203     private AsynchronousSocketChannel finishAccept(FileDescriptor newfd,
 204                                                    final InetSocketAddress remote,
 205                                                    AccessControlContext acc)
 206         throws IOException, SecurityException
 207     {
 208         AsynchronousSocketChannel ch = null;
 209         try {
 210             ch = new UnixAsynchronousSocketChannelImpl(port, newfd, remote);
 211         } catch (IOException x) {
 212             nd.close(newfd);
 213             throw x;
 214         }
 215 
 216         // permission check must always be in initiator's context
 217         try {
 218             if (acc != null) {
 219                 AccessController.doPrivileged(new PrivilegedAction<>() {
 220                     public Void run() {
 221                         SecurityManager sm = System.getSecurityManager();
 222                         if (sm != null) {
 223                             sm.checkAccept(remote.getAddress().getHostAddress(),
 224                                            remote.getPort());
 225                         }
 226                         return null;
 227                     }
 228                 }, acc);
 229             } else {
 230                 SecurityManager sm = System.getSecurityManager();
 231                 if (sm != null) {
 232                     sm.checkAccept(remote.getAddress().getHostAddress(),
 233                                    remote.getPort());
 234                 }
 235             }
 236         } catch (SecurityException x) {
 237             try {
 238                 ch.close();
 239             } catch (Throwable suppressed) {


 270         if (!accepting.compareAndSet(false, true))
 271             throw new AcceptPendingException();
 272 
 273         // attempt accept
 274         FileDescriptor newfd = new FileDescriptor();
 275         InetSocketAddress[] isaa = new InetSocketAddress[1];
 276         Throwable exc = null;
 277         try {
 278             begin();
 279 
 280             int n = accept(this.fd, newfd, isaa);
 281             if (n == IOStatus.UNAVAILABLE) {
 282 
 283                 // need calling context when there is security manager as
 284                 // permission check may be done in a different thread without
 285                 // any application call frames on the stack
 286                 PendingFuture<AsynchronousSocketChannel,Object> result = null;
 287                 synchronized (updateLock) {
 288                     if (handler == null) {
 289                         this.acceptHandler = null;
 290                         result = new PendingFuture<>(this);
 291                         this.acceptFuture = result;
 292                     } else {
 293                         this.acceptHandler = handler;
 294                         this.acceptAttachment = att;
 295                     }
 296                     this.acceptAcc = (System.getSecurityManager() == null) ?
 297                         null : AccessController.getContext();
 298                     this.acceptPending = true;
 299                 }
 300 
 301                 // register for connections
 302                 port.startPoll(fdVal, Net.POLLIN);
 303                 return result;
 304             }
 305         } catch (Throwable x) {
 306             // accept failed
 307             if (x instanceof ClosedChannelException)
 308                 x = new AsynchronousCloseException();
 309             exc = x;
 310         } finally {


< prev index next >