From 873a5ce2eddb65cdfea7fc8bbcae3e8dfef5dfb9 Mon Sep 17 00:00:00 2001 From: Gianluca Oldani Date: Mon, 24 Oct 2022 11:05:07 +0200 Subject: 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 --- cli/dts/lib.deno.unstable.d.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'cli/dts/lib.deno.unstable.d.ts') diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 72f5fc058..85b5911f8 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -1071,6 +1071,17 @@ declare namespace Deno { path: string; } + /** **UNSTABLE**: New API, yet to be vetted. + * + * @category Network + */ + export interface UdpListenOptions extends ListenOptions { + /** When `true` the specified address will be reused, even if another + * process has already bound a socket on it. This effectively steals the + * socket from the listener. Defaults to `false`. */ + reuseAddress?: boolean; + } + /** **UNSTABLE**: New API, yet to be vetted. * * Listen announces on the local transport address. @@ -1110,7 +1121,7 @@ declare namespace Deno { * @category Network */ export function listenDatagram( - options: ListenOptions & { transport: "udp" }, + options: UdpListenOptions & { transport: "udp" }, ): DatagramConn; /** **UNSTABLE**: New API, yet to be vetted. -- cgit v1.2.3