This commit is contained in:
Redkale
2018-04-28 20:43:11 +08:00
parent 16cbabc79d
commit 18459b71c2
2 changed files with 10 additions and 10 deletions

View File

@@ -188,14 +188,14 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
final CompletableFuture<AsyncConnection> future = new CompletableFuture<>(); final CompletableFuture<AsyncConnection> future = new CompletableFuture<>();
try { try {
final AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group); 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<Void, Void>() { channel.connect(address, null, new CompletionHandler<Void, Void>() {
@Override @Override
public void completed(Void result, Void attachment) { 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)); future.complete(create(channel, sslContext, address, readTimeoutSeconds, writeTimeoutSeconds));
} }

View File

@@ -206,6 +206,11 @@ public abstract class ProtocolServer {
public void open() throws IOException { public void open() throws IOException {
group = AsynchronousChannelGroup.withCachedThreadPool(context.executor, 1); group = AsynchronousChannelGroup.withCachedThreadPool(context.executor, 1);
this.serverChannel = AsynchronousServerSocketChannel.open(group); 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 @Override
@@ -240,11 +245,6 @@ public abstract class ProtocolServer {
} }
createCounter.incrementAndGet(); createCounter.incrementAndGet();
livingCounter.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); AsyncConnection conn = AsyncConnection.create(channel, null, context);
conn.livingCounter = livingCounter; conn.livingCounter = livingCounter;
conn.closedCounter = closedCounter; conn.closedCounter = closedCounter;