src/java.base/unix/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java
changeset 54154 1caf2daef7cf
parent 47216 71c04702a3d5
equal deleted inserted replaced
54153:4985c8ca55b9 54154:1caf2daef7cf
     1 /*
     1 /*
     2  * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   139         FileDescriptor newfd = new FileDescriptor();
   139         FileDescriptor newfd = new FileDescriptor();
   140         InetSocketAddress[] isaa = new InetSocketAddress[1];
   140         InetSocketAddress[] isaa = new InetSocketAddress[1];
   141         Throwable exc = null;
   141         Throwable exc = null;
   142         try {
   142         try {
   143             begin();
   143             begin();
   144             int n = accept(this.fd, newfd, isaa);
   144             int n = Net.accept(this.fd, newfd, isaa);
   145 
   145 
   146             // spurious wakeup, is this possible?
   146             // spurious wakeup, is this possible?
   147             if (n == IOStatus.UNAVAILABLE) {
   147             if (n == IOStatus.UNAVAILABLE) {
   148                 synchronized (updateLock) {
   148                 synchronized (updateLock) {
   149                     acceptPending = true;
   149                     acceptPending = true;
   219                 AccessController.doPrivileged(new PrivilegedAction<>() {
   219                 AccessController.doPrivileged(new PrivilegedAction<>() {
   220                     public Void run() {
   220                     public Void run() {
   221                         SecurityManager sm = System.getSecurityManager();
   221                         SecurityManager sm = System.getSecurityManager();
   222                         if (sm != null) {
   222                         if (sm != null) {
   223                             sm.checkAccept(remote.getAddress().getHostAddress(),
   223                             sm.checkAccept(remote.getAddress().getHostAddress(),
   224                                            remote.getPort());
   224                                     remote.getPort());
   225                         }
   225                         }
   226                         return null;
   226                         return null;
   227                     }
   227                     }
   228                 }, acc);
   228                 }, acc);
   229             } else {
   229             } else {
   230                 SecurityManager sm = System.getSecurityManager();
   230                 SecurityManager sm = System.getSecurityManager();
   231                 if (sm != null) {
   231                 if (sm != null) {
   232                     sm.checkAccept(remote.getAddress().getHostAddress(),
   232                     sm.checkAccept(remote.getAddress().getHostAddress(),
   233                                    remote.getPort());
   233                             remote.getPort());
   234                 }
   234                 }
   235             }
   235             }
   236         } catch (SecurityException x) {
   236         } catch (SecurityException x) {
   237             try {
   237             try {
   238                 ch.close();
   238                 ch.close();
   275         InetSocketAddress[] isaa = new InetSocketAddress[1];
   275         InetSocketAddress[] isaa = new InetSocketAddress[1];
   276         Throwable exc = null;
   276         Throwable exc = null;
   277         try {
   277         try {
   278             begin();
   278             begin();
   279 
   279 
   280             int n = accept(this.fd, newfd, isaa);
   280             int n = Net.accept(this.fd, newfd, isaa);
   281             if (n == IOStatus.UNAVAILABLE) {
   281             if (n == IOStatus.UNAVAILABLE) {
   282 
   282 
   283                 // need calling context when there is security manager as
   283                 // need calling context when there is security manager as
   284                 // permission check may be done in a different thread without
   284                 // permission check may be done in a different thread without
   285                 // any application call frames on the stack
   285                 // any application call frames on the stack
   292                     } else {
   292                     } else {
   293                         this.acceptHandler = handler;
   293                         this.acceptHandler = handler;
   294                         this.acceptAttachment = att;
   294                         this.acceptAttachment = att;
   295                     }
   295                     }
   296                     this.acceptAcc = (System.getSecurityManager() == null) ?
   296                     this.acceptAcc = (System.getSecurityManager() == null) ?
   297                         null : AccessController.getContext();
   297                             null : AccessController.getContext();
   298                     this.acceptPending = true;
   298                     this.acceptPending = true;
   299                 }
   299                 }
   300 
   300 
   301                 // register for connections
   301                 // register for connections
   302                 port.startPoll(fdVal, Net.POLLIN);
   302                 port.startPoll(fdVal, Net.POLLIN);
   329         } else {
   329         } else {
   330             Invoker.invokeIndirectly(this, handler, att, child, exc);
   330             Invoker.invokeIndirectly(this, handler, att, child, exc);
   331             return null;
   331             return null;
   332         }
   332         }
   333     }
   333     }
   334 
       
   335     /**
       
   336      * Accept a connection on a socket.
       
   337      *
       
   338      * @implNote Wrap native call to allow instrumentation.
       
   339      */
       
   340     private int accept(FileDescriptor ssfd, FileDescriptor newfd,
       
   341                        InetSocketAddress[] isaa)
       
   342         throws IOException
       
   343     {
       
   344         return accept0(ssfd, newfd, isaa);
       
   345     }
       
   346 
       
   347     // -- Native methods --
       
   348 
       
   349     private static native void initIDs();
       
   350 
       
   351     // Accepts a new connection, setting the given file descriptor to refer to
       
   352     // the new socket and setting isaa[0] to the socket's remote address.
       
   353     // Returns 1 on success, or IOStatus.UNAVAILABLE.
       
   354     //
       
   355     private native int accept0(FileDescriptor ssfd, FileDescriptor newfd,
       
   356                                InetSocketAddress[] isaa)
       
   357         throws IOException;
       
   358 
       
   359     static {
       
   360         IOUtil.load();
       
   361         initIDs();
       
   362     }
       
   363 }
   334 }