diff options
author | Gianluca Oldani <oldanigianluca@gmail.com> | 2022-10-24 11:05:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 09:05:07 +0000 |
commit | 873a5ce2eddb65cdfea7fc8bbcae3e8dfef5dfb9 (patch) | |
tree | c02d782463ae2d8c412118aee35170be6cca7238 /cli/tests/unit/tls_test.ts | |
parent | 38213f1142200e9184d1c5ae1e25ff781248362a (diff) |
feat(ext/net): add reuseAddress option for UDP (#13849)
This commit adds a `reuseAddress` option for UDP sockets. When this
option is enabled, one can listen on an address even though it is
already being listened on from a different process or thread. The new
socket will steal the address from the existing socket.
On Windows and Linux this uses the `SO_REUSEADDR` option, while on other
Unixes this is done with `SO_REUSEPORT`.
This behavior aligns with what libuv does.
TCP sockets still unconditionally set the `SO_REUSEADDR` flag - this
behavior matches Node.js and Go. This PR does not change this behaviour.
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'cli/tests/unit/tls_test.ts')
-rw-r--r-- | cli/tests/unit/tls_test.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/cli/tests/unit/tls_test.ts b/cli/tests/unit/tls_test.ts index 860965e49..df82f6ef6 100644 --- a/cli/tests/unit/tls_test.ts +++ b/cli/tests/unit/tls_test.ts @@ -1376,3 +1376,54 @@ Deno.test( await Promise.all([server(), startTlsClient()]); }, ); + +Deno.test( + { permissions: { read: false, net: true } }, + async function listenTlsWithReuseAddr() { + const resolvable1 = deferred(); + const hostname = "localhost"; + const port = 3500; + + const listener1 = Deno.listenTls({ hostname, port, cert, key }); + + const response1 = encoder.encode( + "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n", + ); + + listener1.accept().then( + async (conn) => { + await conn.write(response1); + setTimeout(() => { + conn.close(); + resolvable1.resolve(); + }, 0); + }, + ); + + const conn1 = await Deno.connectTls({ hostname, port, caCerts }); + conn1.close(); + listener1.close(); + await resolvable1; + + const resolvable2 = deferred(); + const listener2 = Deno.listenTls({ hostname, port, cert, key }); + const response2 = encoder.encode( + "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n", + ); + + listener2.accept().then( + async (conn) => { + await conn.write(response2); + setTimeout(() => { + conn.close(); + resolvable2.resolve(); + }, 0); + }, + ); + + const conn2 = await Deno.connectTls({ hostname, port, caCerts }); + conn2.close(); + listener2.close(); + await resolvable2; + }, +); |