Skip to content

Commit c0d13f7

Browse files
committed
QuicEndpoint#bind returned future should be succeeded with the port of the UDP channel of the bind operation.
1 parent b4193fd commit c0d13f7

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

vertx-core/src/main/java/io/vertx/core/net/QuicEndpoint.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public interface QuicEndpoint extends Measured {
3636
* </ul>
3737
*
3838
* @param address the bind address
39-
* @return a future signaling the success or failure of the bind operation
39+
* @return a future signaling the success or failure of the bind operation, the future completion is the bound this
40+
* endpoint was bound to
4041
*/
41-
Future<Void> bind(SocketAddress address);
42+
Future<Integer> bind(SocketAddress address);
4243

4344
/**
4445
* Close the endpoint and release all associated resources.

vertx-core/src/main/java/io/vertx/core/net/impl/quic/QuicEndpointImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected void handleClose(Completable<Void> completion) {
189189
}
190190

191191
@Override
192-
public Future<Void> bind(SocketAddress address) {
192+
public Future<Integer> bind(SocketAddress address) {
193193
ContextInternal context = vertx.getOrCreateContext();
194194
Future<SslContextProvider> f1 = manager.resolveSslContextProvider(options.getSslOptions(), context);
195195
return f1.compose(sslContextProvider -> {
@@ -203,7 +203,7 @@ public Future<Void> bind(SocketAddress address) {
203203
return bind(context, address, metrics)
204204
.map(ch -> {
205205
handleBind(ch, metrics);
206-
return null;
206+
return ((InetSocketAddress)ch.localAddress()).getPort();
207207
});
208208
});
209209
}

vertx-core/src/test/java/io/vertx/tests/net/quic/QuicServerTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ public void testBind() {
102102

103103
@Test
104104
public void testConnect() throws Exception {
105+
testConnect(9999);
106+
}
107+
108+
@Test
109+
public void testConnectRandomPort() throws Exception {
110+
testConnect(0);
111+
}
112+
113+
private void testConnect(int port) throws Exception {
105114
QuicServer server = QuicServer.create(vertx, serverOptions());
106115
server.handler(conn -> {
107116
assertEquals("test-protocol", conn.applicationLayerProtocol());
@@ -115,11 +124,16 @@ public void testConnect() throws Exception {
115124
});
116125
});
117126
});
118-
server.bind(SocketAddress.inetSocketAddress(9999, "localhost")).await();
127+
int actualPort = server.bind(SocketAddress.inetSocketAddress(port, "localhost")).await();
128+
if (port == 0) {
129+
assertTrue(actualPort > 0);
130+
} else {
131+
assertEquals(port, actualPort);
132+
}
119133
QuicTestClient client = new QuicTestClient(new NioEventLoopGroup(1));
120134
try {
121135
client = new QuicTestClient(new NioEventLoopGroup(1));
122-
QuicTestClient.Connection connection = client.connect(new InetSocketAddress(NetUtil.LOCALHOST4, 9999));
136+
QuicTestClient.Connection connection = client.connect(new InetSocketAddress(NetUtil.LOCALHOST4, actualPort));
123137
QuicTestClient.Stream stream = connection.newStream();
124138
List<String> received = Collections.synchronizedList(new ArrayList<>());
125139
stream.handler(data -> {

0 commit comments

Comments
 (0)