diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-04-08 16:18:14 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 16:18:14 -0600 |
commit | 47061a4539feab411fbbd7db5604f4bd4a532051 (patch) | |
tree | 5f6f17066b6f967b1504ef9b762288ad670d1389 /ext/net/lib.rs | |
parent | 6157c8563484e53b1917c811e94e4b5afa01dc67 (diff) |
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.
Diffstat (limited to 'ext/net/lib.rs')
-rw-r--r-- | ext/net/lib.rs | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/ext/net/lib.rs b/ext/net/lib.rs index d6e1d9dc2..d137aa315 100644 --- a/ext/net/lib.rs +++ b/ext/net/lib.rs @@ -7,9 +7,9 @@ pub mod ops_tls; pub mod ops_unix; pub mod raw; pub mod resolve_addr; +mod tcp; use deno_core::error::AnyError; -use deno_core::op2; use deno_core::OpState; use deno_tls::rustls::RootCertStore; use deno_tls::RootCertStoreProvider; @@ -93,21 +93,13 @@ deno_core::extension!(deno_net, ops_tls::op_net_accept_tls, ops_tls::op_tls_handshake, - #[cfg(unix)] ops_unix::op_net_accept_unix, - #[cfg(unix)] ops_unix::op_net_connect_unix<P>, - #[cfg(unix)] ops_unix::op_net_listen_unix<P>, - #[cfg(unix)] ops_unix::op_net_listen_unixpacket<P>, - #[cfg(unix)] ops_unix::op_node_unstable_net_listen_unixpacket<P>, - #[cfg(unix)] ops_unix::op_net_recv_unixpacket, - #[cfg(unix)] ops_unix::op_net_send_unixpacket<P>, - - #[cfg(not(unix))] op_net_accept_unix, - #[cfg(not(unix))] op_net_connect_unix, - #[cfg(not(unix))] op_net_listen_unix, - #[cfg(not(unix))] op_net_listen_unixpacket, - #[cfg(not(unix))] op_node_unstable_net_listen_unixpacket, - #[cfg(not(unix))] op_net_recv_unixpacket, - #[cfg(not(unix))] op_net_send_unixpacket, + ops_unix::op_net_accept_unix, + ops_unix::op_net_connect_unix<P>, + ops_unix::op_net_listen_unix<P>, + ops_unix::op_net_listen_unixpacket<P>, + ops_unix::op_node_unstable_net_listen_unixpacket<P>, + ops_unix::op_net_recv_unixpacket, + ops_unix::op_net_send_unixpacket<P>, ], esm = [ "01_net.js", "02_tls.js" ], options = { @@ -124,19 +116,32 @@ deno_core::extension!(deno_net, }, ); -macro_rules! stub_op { - ($name:ident) => { - #[op2(fast)] - fn $name() { - panic!("Unsupported on non-unix platforms") - } - }; -} +/// Stub ops for non-unix platforms. +#[cfg(not(unix))] +mod ops_unix { + use crate::NetPermissions; + use deno_core::op2; -stub_op!(op_net_accept_unix); -stub_op!(op_net_connect_unix); -stub_op!(op_net_listen_unix); -stub_op!(op_net_listen_unixpacket); -stub_op!(op_node_unstable_net_listen_unixpacket); -stub_op!(op_net_recv_unixpacket); -stub_op!(op_net_send_unixpacket); + macro_rules! stub_op { + ($name:ident) => { + #[op2(fast)] + pub fn $name() { + panic!("Unsupported on non-unix platforms") + } + }; + ($name:ident<P>) => { + #[op2(fast)] + pub fn $name<P: NetPermissions>() { + panic!("Unsupported on non-unix platforms") + } + }; + } + + stub_op!(op_net_accept_unix); + stub_op!(op_net_connect_unix<P>); + stub_op!(op_net_listen_unix<P>); + stub_op!(op_net_listen_unixpacket<P>); + stub_op!(op_node_unstable_net_listen_unixpacket<P>); + stub_op!(op_net_recv_unixpacket); + stub_op!(op_net_send_unixpacket<P>); +} |