From 81a6504e670d32bdc5e0a8328c328fdf8e208913 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 15 Dec 2023 16:20:05 +0530 Subject: refactor: setup child process pipe in Rust (#21579) Avoid passing the fd into JS and back into Rust. Instead we setup the child's end of the pipe directly using a special Rust op. --- ext/node/ops/ipc.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ext/node/ops') diff --git a/ext/node/ops/ipc.rs b/ext/node/ops/ipc.rs index d1aeeb40c..afaccc49f 100644 --- a/ext/node/ops/ipc.rs +++ b/ext/node/ops/ipc.rs @@ -6,6 +6,8 @@ pub use unix::*; #[cfg(windows)] pub use windows::*; +pub struct ChildPipeFd(pub i32); + #[cfg(unix)] mod unix { use std::cell::RefCell; @@ -46,6 +48,22 @@ mod unix { Ok(state.resource_table.add(IpcJsonStreamResource::new(fd)?)) } + // Open IPC pipe from bootstrap options. + #[op2] + #[smi] + pub fn op_node_child_ipc_pipe( + state: &mut OpState, + ) -> Result, AnyError> { + let fd = match state.try_borrow_mut::() { + Some(child_pipe_fd) => child_pipe_fd.0, + None => return Ok(None), + }; + + Ok(Some( + state.resource_table.add(IpcJsonStreamResource::new(fd)?), + )) + } + #[op2(async)] pub async fn op_node_ipc_write( state: Rc>, @@ -492,6 +510,12 @@ mod windows { Err(deno_core::error::not_supported()) } + #[op2(fast)] + #[smi] + pub fn op_node_child_ipc_pipe() -> Result { + Ok(-1) + } + #[op2(async)] pub async fn op_node_ipc_write() -> Result<(), AnyError> { Err(deno_core::error::not_supported()) -- cgit v1.2.3