| 18 | import java.net.Socket; |
| 19 | |
| 20 | public class ServerSocketChannel extends SelectableChannel { |
| 21 | private final SocketChannel channel; |
| 22 | |
| 23 | private ServerSocketChannel() throws IOException { |
| 24 | channel = new SocketChannel(); |
| 25 | } |
| 26 | |
| 27 | public static ServerSocketChannel open() throws IOException { |
| 28 | Socket.init(); |
| 29 | |
| 30 | return new ServerSocketChannel(); |
| 31 | } |
| 32 | |
| 33 | public int socketFD() { |
| 34 | return channel.socketFD(); |
| 35 | } |
| 36 | |
| 37 | public void handleReadyOps(int ops) { |
| 38 | channel.handleReadyOps(ops); |
| 39 | } |
| 40 | |
| 41 | public SelectableChannel configureBlocking(boolean v) throws IOException { |
| 42 | return channel.configureBlocking(v); |
| 43 | } |
| 44 | |
| 45 | public void close() throws IOException { |
| 46 | channel.close(); |
| 47 | } |
| 48 | |
| 49 | public SocketChannel accept() throws IOException { |
| 50 | SocketChannel c = new SocketChannel(); |
| 51 | c.socket = doAccept(); |
| 52 | c.connected = true; |
| 53 | return c; |
| 54 | } |
| 55 | |
| 56 | public ServerSocket socket() { |
| 57 | return new Handle(); |
| 58 | } |
| 59 | |
| 60 | private int doAccept() throws IOException { |
| 61 | while (true) { |
| 62 | int s = natDoAccept(channel.socket); |
| 63 | if (s != -1) { |
| 64 | return s; |
| 65 | } |
| 66 | // todo: throw ClosedByInterruptException if this thread was |
| 67 | // interrupted during the accept call |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | private void doListen(int socket, int host, int port) throws IOException { |
| 72 | Socket.init(); |
| 73 | |
| 74 | natDoListen(socket, host, port); |
| 75 | } |
| 76 | |
| 77 | public class Handle extends ServerSocket { |
nothing calls this directly
no outgoing calls
no test coverage detected