< prev index next >

src/java.base/share/classes/sun/nio/ch/ServerSocketAdaptor.java

Print this page
rev 48993 : imported patch nio

*** 32,42 **** import java.net.Socket; import java.net.SocketAddress; 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; import java.nio.channels.SocketChannel; --- 32,41 ----
*** 49,59 **** // class ServerSocketAdaptor // package-private extends ServerSocket { - // The channel being adapted private final ServerSocketChannelImpl ssc; // Timeout "option" value for accepts private volatile int timeout; --- 48,57 ----
*** 65,81 **** throw new Error(x); } } // ## super will create a useless impl ! private ServerSocketAdaptor(ServerSocketChannelImpl ssc) ! throws IOException ! { this.ssc = ssc; } - public void bind(SocketAddress local) throws IOException { bind(local, 50); } public void bind(SocketAddress local, int backlog) throws IOException { --- 63,76 ---- throw new Error(x); } } // ## super will create a useless impl ! private ServerSocketAdaptor(ServerSocketChannelImpl ssc) throws IOException { this.ssc = ssc; } public void bind(SocketAddress local) throws IOException { bind(local, 50); } public void bind(SocketAddress local, int backlog) throws IOException {
*** 87,148 **** Net.translateException(x); } } public InetAddress getInetAddress() { ! if (!ssc.isBound()) return null; ! return Net.getRevealedLocalAddress(ssc.localAddress()).getAddress(); ! } public int getLocalPort() { ! if (!ssc.isBound()) return -1; ! return Net.asInetSocketAddress(ssc.localAddress()).getPort(); } - public Socket accept() throws IOException { synchronized (ssc.blockingLock()) { try { if (!ssc.isBound()) throw new NotYetBoundException(); ! if (timeout == 0) { // for compatibility reasons: accept connection if available // when configured non-blocking SocketChannel sc = ssc.accept(); if (sc == null && !ssc.isBlocking()) throw new IllegalBlockingModeException(); return sc.socket(); } 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) { } ! } } catch (Exception x) { Net.translateException(x); assert false; return null; // Never happens } --- 82,135 ---- Net.translateException(x); } } public InetAddress getInetAddress() { ! InetSocketAddress local = ssc.localAddress(); ! if (local == null) { return null; ! } else { ! return Net.getRevealedLocalAddress(local).getAddress(); ! } } public int getLocalPort() { ! InetSocketAddress local = ssc.localAddress(); ! if (local == null) { return -1; ! } else { ! return local.getPort(); ! } } public Socket accept() throws IOException { synchronized (ssc.blockingLock()) { try { if (!ssc.isBound()) throw new NotYetBoundException(); ! long to = this.timeout; ! if (to == 0) { // for compatibility reasons: accept connection if available // when configured non-blocking SocketChannel sc = ssc.accept(); if (sc == null && !ssc.isBlocking()) throw new IllegalBlockingModeException(); return sc.socket(); } if (!ssc.isBlocking()) throw new IllegalBlockingModeException(); 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; return null; // Never happens }
*** 214,220 **** } catch (IOException x) { Net.translateToSocketException(x); return -1; // Never happens } } - } --- 201,206 ----
< prev index next >