Skip to main content

SupervisorSocket

Struct SupervisorSocket 

Source
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

Source

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)
Source

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.

Source

pub fn connect(path: &Path) -> Result<Self>

Connect to a supervisor socket at the given path.

Source

pub fn from_stream(stream: UnixStream) -> Self

Wrap an existing UnixStream (e.g., from an inherited fd after fork).

Source

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.

Source

pub fn send_message(&mut self, msg: &SupervisorMessage) -> Result<()>

Send a message from child to supervisor.

Source

pub fn recv_message(&mut self) -> Result<SupervisorMessage>

Receive a message from child (supervisor side).

Source

pub fn send_response(&mut self, resp: &SupervisorResponse) -> Result<()>

Send a response from supervisor to child.

Source

pub fn recv_response(&mut self) -> Result<SupervisorResponse>

Receive a response from supervisor (child side).

Source

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.

Source

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.

Source

pub fn peer_pid(&self) -> Result<u32>

Authenticate the peer using platform-specific mechanisms.

On Linux, uses SO_PEERCRED to get the peer’s PID/UID/GID. On macOS, combines LOCAL_PEERPID and getpeereid.

Returns the peer’s PID.

Source

pub fn set_read_timeout(&self, timeout: Option<Duration>) -> Result<()>

Set a read timeout on the socket.

Trait Implementations§

Source§

impl Drop for SupervisorSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more