--- old/src/java.base/share/classes/sun/nio/ch/ServerSocketAdaptor.java 2018-02-27 14:15:28.000000000 +0000 +++ new/src/java.base/share/classes/sun/nio/ch/ServerSocketAdaptor.java 2018-02-27 14:15:28.000000000 +0000 @@ -34,7 +34,6 @@ import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.StandardSocketOptions; -import java.nio.channels.ClosedChannelException; import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.NotYetBoundException; import java.nio.channels.ServerSocketChannel; @@ -51,7 +50,6 @@ class ServerSocketAdaptor // package-private extends ServerSocket { - // The channel being adapted private final ServerSocketChannelImpl ssc; @@ -67,13 +65,10 @@ } // ## super will create a useless impl - private ServerSocketAdaptor(ServerSocketChannelImpl ssc) - throws IOException - { + private ServerSocketAdaptor(ServerSocketChannelImpl ssc) throws IOException { this.ssc = ssc; } - public void bind(SocketAddress local) throws IOException { bind(local, 50); } @@ -89,26 +84,31 @@ } public InetAddress getInetAddress() { - if (!ssc.isBound()) + InetSocketAddress local = ssc.localAddress(); + if (local == null) { return null; - return Net.getRevealedLocalAddress(ssc.localAddress()).getAddress(); - + } else { + return Net.getRevealedLocalAddress(local).getAddress(); + } } public int getLocalPort() { - if (!ssc.isBound()) + InetSocketAddress local = ssc.localAddress(); + if (local == null) { return -1; - return Net.asInetSocketAddress(ssc.localAddress()).getPort(); + } else { + return local.getPort(); + } } - public Socket accept() throws IOException { synchronized (ssc.blockingLock()) { try { if (!ssc.isBound()) throw new NotYetBoundException(); - if (timeout == 0) { + long to = this.timeout; + if (to == 0) { // for compatibility reasons: accept connection if available // when configured non-blocking SocketChannel sc = ssc.accept(); @@ -119,28 +119,15 @@ if (!ssc.isBlocking()) throw new IllegalBlockingModeException(); - ssc.configureBlocking(false); - try { - SocketChannel sc; - if ((sc = ssc.accept()) != null) - return sc.socket(); - long to = timeout; - for (;;) { - if (!ssc.isOpen()) - throw new ClosedChannelException(); - long st = System.currentTimeMillis(); - int result = ssc.poll(Net.POLLIN, to); - if (result > 0 && ((sc = ssc.accept()) != null)) - return sc.socket(); - to -= System.currentTimeMillis() - st; - if (to <= 0) - throw new SocketTimeoutException(); - } - } finally { - try { - ssc.configureBlocking(true); - } catch (ClosedChannelException e) { } + for (;;) { + long st = System.currentTimeMillis(); + if (ssc.pollAccept(to)) + return ssc.accept().socket(); + to -= System.currentTimeMillis() - st; + if (to <= 0) + throw new SocketTimeoutException(); } + } catch (Exception x) { Net.translateException(x); assert false; @@ -216,5 +203,4 @@ return -1; // Never happens } } - }