From 47061a4539feab411fbbd7db5604f4bd4a532051 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Mon, 8 Apr 2024 16:18:14 -0600 Subject: feat(ext/net): Refactor TCP socket listeners for future clustering mode (#23037) Changes: - Implements a TCP socket listener that will allow for round-robin load-balancing in-process. - Cleans up the raw networking code to make it easier to work with. --- ext/net/ops_unix.rs | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'ext/net/ops_unix.rs') diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs index be3e9d153..7d2f6af3c 100644 --- a/ext/net/ops_unix.rs +++ b/ext/net/ops_unix.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use crate::io::UnixStreamResource; +use crate::raw::NetworkListenerResource; use crate::NetPermissions; use deno_core::error::bad_resource; use deno_core::error::custom_error; @@ -32,21 +33,6 @@ pub fn into_string(s: std::ffi::OsString) -> Result { }) } -pub(crate) struct UnixListenerResource { - pub listener: AsyncRefCell, - cancel: CancelHandle, -} - -impl Resource for UnixListenerResource { - fn name(&self) -> Cow { - "unixListener".into() - } - - fn close(self: Rc) { - self.cancel.cancel(); - } -} - pub struct UnixDatagramResource { pub socket: AsyncRefCell, pub cancel: CancelHandle, @@ -81,7 +67,7 @@ pub async fn op_net_accept_unix( let resource = state .borrow() .resource_table - .get::(rid) + .get::>(rid) .map_err(|_| bad_resource("Listener has been closed"))?; let listener = RcRef::map(&resource, |r| &r.listener) .try_borrow_mut() @@ -206,10 +192,7 @@ where let listener = UnixListener::bind(address_path)?; let local_addr = listener.local_addr()?; let pathname = local_addr.as_pathname().map(pathstring).transpose()?; - let listener_resource = UnixListenerResource { - listener: AsyncRefCell::new(listener), - cancel: Default::default(), - }; + let listener_resource = NetworkListenerResource::new(listener); let rid = state.resource_table.add(listener_resource); Ok((rid, pathname)) } -- cgit v1.2.3