This commit is contained in:
@@ -34,15 +34,20 @@ public final class Transport {
|
|||||||
|
|
||||||
protected static final boolean supportTcpNoDelay;
|
protected static final boolean supportTcpNoDelay;
|
||||||
|
|
||||||
|
protected static final boolean supportKeepAlive;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
boolean tcpNoDelay = false;
|
boolean tcpNoDelay = false;
|
||||||
|
boolean keepAlive = false;
|
||||||
try {
|
try {
|
||||||
AsynchronousSocketChannel channel = AsynchronousSocketChannel.open();
|
AsynchronousSocketChannel channel = AsynchronousSocketChannel.open();
|
||||||
tcpNoDelay = channel.supportedOptions().contains(StandardSocketOptions.TCP_NODELAY);
|
tcpNoDelay = channel.supportedOptions().contains(StandardSocketOptions.TCP_NODELAY);
|
||||||
|
keepAlive = channel.supportedOptions().contains(StandardSocketOptions.SO_KEEPALIVE);
|
||||||
channel.close();
|
channel.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
supportTcpNoDelay = tcpNoDelay;
|
supportTcpNoDelay = tcpNoDelay;
|
||||||
|
supportKeepAlive = keepAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final AtomicInteger seq = new AtomicInteger(-1);
|
protected final AtomicInteger seq = new AtomicInteger(-1);
|
||||||
@@ -265,6 +270,7 @@ public final class Transport {
|
|||||||
CompletableFuture future = new CompletableFuture();
|
CompletableFuture future = new CompletableFuture();
|
||||||
final AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group);
|
final AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group);
|
||||||
if (supportTcpNoDelay) channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
if (supportTcpNoDelay) channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
||||||
|
if (supportKeepAlive) channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
|
||||||
channel.connect(one.address, one, new CompletionHandler<Void, TransportNode>() {
|
channel.connect(one.address, one, new CompletionHandler<Void, TransportNode>() {
|
||||||
@Override
|
@Override
|
||||||
public void completed(Void result, TransportNode attachment) {
|
public void completed(Void result, TransportNode attachment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user