summaryrefslogtreecommitdiff
path: root/ext/net/ops.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-10-26 21:04:27 +0200
committerGitHub <noreply@github.com>2022-10-26 19:04:27 +0000
commitf4f1f4f0b64030b744cfb43693af321ea8332bf4 (patch)
tree9d4e1fcf9ea9b92ef5a863fcd449edf8c0c9a834 /ext/net/ops.rs
parentde580cedd24be22dc267d5b92538364ed9998a46 (diff)
feat(ext/net): reusePort for TCP on Linux (#16398)
Diffstat (limited to 'ext/net/ops.rs')
-rw-r--r--ext/net/ops.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/ext/net/ops.rs b/ext/net/ops.rs
index 9a6d95586..e6420bf9e 100644
--- a/ext/net/ops.rs
+++ b/ext/net/ops.rs
@@ -246,10 +246,14 @@ impl Resource for UdpSocketResource {
fn op_net_listen_tcp<NP>(
state: &mut OpState,
addr: IpAddr,
+ reuse_port: bool,
) -> Result<(ResourceId, IpAddr), AnyError>
where
NP: NetPermissions + 'static,
{
+ if reuse_port {
+ super::check_unstable(state, "Deno.listen({ reusePort: true })");
+ }
state
.borrow_mut::<NP>()
.check_net(&(&addr.hostname, Some(addr.port)), "Deno.listen()")?;
@@ -264,6 +268,10 @@ where
let socket = Socket::new(domain, Type::STREAM, None)?;
#[cfg(not(windows))]
socket.set_reuse_address(true)?;
+ if reuse_port {
+ #[cfg(target_os = "linux")]
+ socket.set_reuse_port(true)?;
+ }
let socket_addr = socket2::SockAddr::from(addr);
socket.bind(&socket_addr)?;
socket.listen(128)?;