/** * Set a {@link ChannelOption} value for low level connection settings like {@code SO_TIMEOUT} * or {@code SO_KEEPALIVE}. This will apply to parent selector channel. * * @param key the option key * @param value the option value * @param <T> the option type * * @return new {@link TcpServer} * * @see ServerBootstrap#childOption(ChannelOption, Object) */ public final <T> TcpServer selectorOption(ChannelOption<T> key, T value) { return option(key, value); }
/** * Set a {@link ChannelOption} value for low level connection settings like {@code SO_TIMEOUT} * or {@code SO_KEEPALIVE}. This will apply to parent selector channel. * * @param key the option key * @param value the option value * @param <T> the option type * * @return new {@link TcpServer} * * @see ServerBootstrap#childOption(ChannelOption, Object) */ public final <T> TcpServer selectorOption(ChannelOption<T> key, T value) { return option(key, value); }
/** * Creates TcpServer. * * @return tcp server */ private TcpServer newTcpServer() { return TcpServer.create() .runOn(loopResources) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_REUSEADDR, true) .addressSupplier(() -> new InetSocketAddress(config.getPort())) .bootstrap(b -> BootstrapHandlers.updateConfiguration(b, "inbound", channelInitializer)); }
@Test @Ignore public void startContentServer() { Random random = new Random(0); byte[] content = new byte[1024 * 10]; random.nextBytes(content); HttpServer server = HttpServer.create() .port(CONTENT_SERVER_PORT) .tcpConfiguration(tcpServer -> tcpServer.host("0.0.0.0") .option(ChannelOption.SO_LINGER, -1)); server.route(routes -> routes.get("/**", (req, res) -> res.header("Content-length", String.valueOf(content.length)) .header("Content-type", "application/octet-stream") .header("Connection", "Close") .sendByteArray(Flux.just(content)))) .wiretap(true) .bindNow(); }