This commit is contained in:
@@ -127,15 +127,15 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
|
||||
*
|
||||
* @param address 连接点子
|
||||
* @param group 连接AsynchronousChannelGroup
|
||||
* @param readTimeoutSecond0 读取超时秒数
|
||||
* @param writeTimeoutSecond0 写入超时秒数
|
||||
* @param readTimeoutSecond 读取超时秒数
|
||||
* @param writeTimeoutSecond 写入超时秒数
|
||||
*
|
||||
* @return 连接CompletableFuture
|
||||
* @throws java.io.IOException 异常
|
||||
*/
|
||||
public static CompletableFuture<AsyncConnection> createTCP(final AsynchronousChannelGroup group, final SocketAddress address,
|
||||
final int readTimeoutSecond0, final int writeTimeoutSecond0) throws IOException {
|
||||
return createTCP(group, address, false, readTimeoutSecond0, writeTimeoutSecond0);
|
||||
final int readTimeoutSecond, final int writeTimeoutSecond) throws IOException {
|
||||
return createTCP(group, address, false, readTimeoutSecond, writeTimeoutSecond);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,14 +144,14 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
|
||||
* @param address 连接点子
|
||||
* @param group 连接AsynchronousChannelGroup
|
||||
* @param noDelay TcpNoDelay
|
||||
* @param readTimeoutSecond0 读取超时秒数
|
||||
* @param writeTimeoutSecond0 写入超时秒数
|
||||
* @param readTimeoutSecond 读取超时秒数
|
||||
* @param writeTimeoutSecond 写入超时秒数
|
||||
*
|
||||
* @return 连接CompletableFuture
|
||||
* @throws java.io.IOException 异常
|
||||
*/
|
||||
public static CompletableFuture<AsyncConnection> createTCP(final AsynchronousChannelGroup group, final SocketAddress address,
|
||||
final boolean noDelay, final int readTimeoutSecond0, final int writeTimeoutSecond0) throws IOException {
|
||||
final boolean noDelay, final int readTimeoutSecond, final int writeTimeoutSecond) throws IOException {
|
||||
final CompletableFuture future = new CompletableFuture();
|
||||
final AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group);
|
||||
channel.connect(address, null, new CompletionHandler<Void, Void>() {
|
||||
@@ -163,7 +163,7 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
future.complete(create(channel, address, readTimeoutSecond0, writeTimeoutSecond0));
|
||||
future.complete(create(channel, address, readTimeoutSecond, writeTimeoutSecond));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -600,8 +600,8 @@ public abstract class AsyncConnection implements AsynchronousByteChannel, AutoCl
|
||||
return create(ch, null, 0, 0);
|
||||
}
|
||||
|
||||
public static AsyncConnection create(final AsynchronousSocketChannel ch, final SocketAddress addr0, final int readTimeoutSecond0, final int writeTimeoutSecond0) {
|
||||
return new AIOTCPAsyncConnection(ch, addr0, readTimeoutSecond0, writeTimeoutSecond0);
|
||||
public static AsyncConnection create(final AsynchronousSocketChannel ch, final SocketAddress addr0, final int readTimeoutSecond, final int writeTimeoutSecond) {
|
||||
return new AIOTCPAsyncConnection(ch, addr0, readTimeoutSecond, writeTimeoutSecond);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -244,21 +244,16 @@ public final class Transport {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channel = AsynchronousSocketChannel.open(group);
|
||||
if (supportTcpNoDelay) channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
|
||||
channel.connect(addr).get(2, TimeUnit.SECONDS);
|
||||
return AsyncConnection.createTCP(group, addr, supportTcpNoDelay, 6, 6);
|
||||
}
|
||||
if (channel == null) return CompletableFuture.completedFuture(null);
|
||||
return CompletableFuture.completedFuture(AsyncConnection.create(channel, addr, 3000, 3000));
|
||||
return CompletableFuture.completedFuture(AsyncConnection.create(channel, addr, 6, 6));
|
||||
} else { // UDP
|
||||
if (rand) addr = this.transportAddres[0].address;
|
||||
DatagramChannel channel = DatagramChannel.open();
|
||||
channel.configureBlocking(true);
|
||||
channel.connect(addr);
|
||||
return CompletableFuture.completedFuture(AsyncConnection.create(channel, addr, true, 3000, 3000));
|
||||
// AsyncDatagramChannel channel = AsyncDatagramChannel.open(group);
|
||||
// channel.connect(addr);
|
||||
// return AsyncConnection.create(channel, addr, true, 3000, 3000);
|
||||
return CompletableFuture.completedFuture(AsyncConnection.create(channel, addr, true, 6, 6));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("transport address = " + addr, ex);
|
||||
|
||||
Reference in New Issue
Block a user