summaryrefslogtreecommitdiff
path: root/ext/node/ops/ipc.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-12-15 16:20:05 +0530
committerGitHub <noreply@github.com>2023-12-15 11:50:05 +0100
commit81a6504e670d32bdc5e0a8328c328fdf8e208913 (patch)
tree27a90846e42edd1863e45e9792375d7777f10667 /ext/node/ops/ipc.rs
parent62e3f5060ef9cc6a31b3e496dd15548c0abd07e6 (diff)
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.
Diffstat (limited to 'ext/node/ops/ipc.rs')
-rw-r--r--ext/node/ops/ipc.rs24
1 files changed, 24 insertions, 0 deletions
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<Option<ResourceId>, AnyError> {
+ let fd = match state.try_borrow_mut::<crate::ChildPipeFd>() {
+ 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<RefCell<OpState>>,
@@ -492,6 +510,12 @@ mod windows {
Err(deno_core::error::not_supported())
}
+ #[op2(fast)]
+ #[smi]
+ pub fn op_node_child_ipc_pipe() -> Result<i32, AnyError> {
+ Ok(-1)
+ }
+
#[op2(async)]
pub async fn op_node_ipc_write() -> Result<(), AnyError> {
Err(deno_core::error::not_supported())