private static ServerSocketChannel createServerSocketChannel(Spec spec) throws ListenFailedException { ServerSocketChannel serverChannel = null; try { serverChannel = ServerSocketChannel.open(); serverChannel.configureBlocking(true); if (spec.port() != 0) { serverChannel.socket().setReuseAddress(true); } serverChannel.socket().bind(spec.address(), 500); } catch (Exception e) { if (serverChannel != null) { try { serverChannel.socket().close(); } catch (Exception ignore) {} } throw new ListenFailedException("Failed to listen to " + spec, e); } return serverChannel; }
public Connection connect() { if (spec == null || spec.malformed()) { setLostReason(new IllegalArgumentException("jrt: malformed or missing spec")); return this; } try { socket = parent.createCryptoSocket(SocketChannel.open(spec.address()), false); } catch (Exception e) { setLostReason(e); } return this; }