public void run() {
try {
ByteBuffer bb = ByteBuffer.allocateDirect(64 * 1024);
System.err.println("Accepting connect on " + ssc.socket().getLocalPort());
while (!Thread.interrupted()) {
SocketChannel sc = ssc.accept();
if (BUSY)
sc.configureBlocking(false);
String ra = sc.socket().getInetAddress().toString();
System.err.println("... connect to " + ra);
try {
sc.socket().setTcpNoDelay(true);
while (sc.read(bb) >= 0) {
bb.flip();
// System.out.println("e "+bb.remaining());
IOTools.writeAllOrEOF(sc, bb);
bb.clear();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
sc.close();
}
}
} catch (ClosedByInterruptException ignored) {
} catch (IOException e) {
e.printStackTrace();