From 18459b71c23d8cb2ff75ec0d087f54e068a62dbd Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Sat, 28 Apr 2018 20:43:11 +0800 Subject: [PATCH] --- src/org/redkale/net/AsyncConnection.java | 10 +++++----- src/org/redkale/net/ProtocolServer.java | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/org/redkale/net/AsyncConnection.java b/src/org/redkale/net/AsyncConnection.java index fcf284491..38f7d63c1 100644 --- a/src/org/redkale/net/AsyncConnection.java +++ b/src/org/redkale/net/AsyncConnection.java @@ -188,14 +188,14 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl final CompletableFuture future = new CompletableFuture<>(); try { final AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group); + try { + if (noDelay) channel.setOption(StandardSocketOptions.TCP_NODELAY, true); + if (supportTcpKeepAlive()) channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); + } catch (IOException e) { + } channel.connect(address, null, new CompletionHandler() { @Override public void completed(Void result, Void attachment) { - try { - if (noDelay) channel.setOption(StandardSocketOptions.TCP_NODELAY, true); - if (supportTcpKeepAlive()) channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); - } catch (IOException e) { - } future.complete(create(channel, sslContext, address, readTimeoutSeconds, writeTimeoutSeconds)); } diff --git a/src/org/redkale/net/ProtocolServer.java b/src/org/redkale/net/ProtocolServer.java index 3284ec81f..b76beffd8 100644 --- a/src/org/redkale/net/ProtocolServer.java +++ b/src/org/redkale/net/ProtocolServer.java @@ -206,6 +206,11 @@ public abstract class ProtocolServer { public void open() throws IOException { group = AsynchronousChannelGroup.withCachedThreadPool(context.executor, 1); this.serverChannel = AsynchronousServerSocketChannel.open(group); + try { + if (supportTcpNoDelay()) this.serverChannel.setOption(StandardSocketOptions.TCP_NODELAY, true); + if (supportTcpKeepAlive()) this.serverChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); + } catch (IOException e) { + } } @Override @@ -240,11 +245,6 @@ public abstract class ProtocolServer { } createCounter.incrementAndGet(); livingCounter.incrementAndGet(); - try { - if (supportTcpNoDelay()) channel.setOption(StandardSocketOptions.TCP_NODELAY, true); - if (supportTcpKeepAlive()) channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); - } catch (IOException e) { - } AsyncConnection conn = AsyncConnection.create(channel, null, context); conn.livingCounter = livingCounter; conn.closedCounter = closedCounter;