pub struct SupervisorSocket { /* private fields */ }Expand description
A Unix domain socket for supervisor IPC.
Created by the supervisor before fork. The child inherits one end via the forked file descriptor table, or the fd is explicitly passed.
§Protocol
Messages are length-prefixed JSON:
[4 bytes: u32 big-endian length][N bytes: JSON payload]When granting access, the supervisor sends the response message AND passes
an opened file descriptor via SCM_RIGHTS ancillary data.
Implementations§
Source§impl SupervisorSocket
impl SupervisorSocket
Sourcepub fn pair() -> Result<(Self, Self)>
pub fn pair() -> Result<(Self, Self)>
Create a connected socket pair for supervisor-child IPC.
Returns (supervisor_end, child_end). Call this before fork:
- The supervisor keeps
supervisor_end - The child inherits
child_end(or it’s passed explicitly)
Sourcepub fn bind(path: &Path) -> Result<Self>
pub fn bind(path: &Path) -> Result<Self>
Create a supervisor socket bound to a filesystem path.
The supervisor binds and listens; the child connects after fork. The socket file is cleaned up on drop.
Sourcepub fn from_stream(stream: UnixStream) -> Self
pub fn from_stream(stream: UnixStream) -> Self
Wrap an existing UnixStream (e.g., from an inherited fd after fork).
Sourcepub fn as_raw_fd(&self) -> RawFd
pub fn as_raw_fd(&self) -> RawFd
Get the raw file descriptor for this socket.
Useful for passing to the child process via environment variable
or for select()/poll() integration.
Sourcepub fn send_message(&mut self, msg: &SupervisorMessage) -> Result<()>
pub fn send_message(&mut self, msg: &SupervisorMessage) -> Result<()>
Send a message from child to supervisor.
Sourcepub fn recv_message(&mut self) -> Result<SupervisorMessage>
pub fn recv_message(&mut self) -> Result<SupervisorMessage>
Receive a message from child (supervisor side).
Sourcepub fn send_response(&mut self, resp: &SupervisorResponse) -> Result<()>
pub fn send_response(&mut self, resp: &SupervisorResponse) -> Result<()>
Send a response from supervisor to child.
Sourcepub fn recv_response(&mut self) -> Result<SupervisorResponse>
pub fn recv_response(&mut self) -> Result<SupervisorResponse>
Receive a response from supervisor (child side).
Sourcepub fn send_fd(&self, fd: RawFd) -> Result<()>
pub fn send_fd(&self, fd: RawFd) -> Result<()>
Send a file descriptor to the peer via SCM_RIGHTS.
Used by the supervisor to pass an opened fd for a granted path.
Sourcepub fn recv_fd(&self) -> Result<OwnedFd>
pub fn recv_fd(&self) -> Result<OwnedFd>
Receive a file descriptor from the peer via SCM_RIGHTS.
Used by the child to receive an opened fd for a granted path.
Returns an OwnedFd that the caller is responsible for.