Function spawn_server

Source
pub fn spawn_server(
    index: usize,
    source: Source,
    argv: &[&CStr],
) -> Result<(Pipe, Pipe), IpcError>
Expand description

Spawns a new server process and sets up pipes.

This function creates two pairs of pipes for communication between the parent and child processes. It then spawns a new process using the specified index and source, passing the provided arguments to the new process. The function returns the read and write file descriptors for the parent process to communicate with the child process.

§Arguments

  • index - The index of the cell to spawn.
  • source - The source of the cell (e.g., Source::CellDep).
  • argv - A slice of C strings representing the arguments to pass to the new process.

§Returns

A Result containing a tuple of two Pipe representing the read and write file descriptors for the parent process, or an IpcError if an error occurs.

§Errors

This function returns an IpcError if any of the following syscalls fail:

  • pipe - If creating a pipe fails.
  • spawn - If spawning the new process fails.

§Example

use ckb_script_ipc_common::spawn::spawn_server;

let (read_pipe, write_pipe) = spawn_server(
    0,
    Source::CellDep,
    &[CString::new("demo").unwrap().as_ref()],
).expect("Failed to spawn server");