pub struct IpcChannel { /* private fields */ }Expand description
IPC channel — a buffered Unix socket pair endpoint that speaks newline-delimited JSON, optionally carrying a RawFd per message via SCM_RIGHTS ancillary data.
One channel = one endpoint of a socketpair(AF_UNIX, SOCK_STREAM). The
other endpoint belongs to the peer (parent ↔ child).
Implementations§
Source§impl IpcChannel
impl IpcChannel
Sourcepub fn new(socket: UnixStream) -> IpcChannel
pub fn new(socket: UnixStream) -> IpcChannel
Wrap an existing connected UnixStream as an IPC channel endpoint.
Sourcepub fn send_json(&mut self, json: &str) -> Result<(), Error>
pub fn send_json(&mut self, json: &str) -> Result<(), Error>
Send a JSON message terminated by \n. No fd is attached.
Sourcepub fn send_handle(&mut self, json: &str, fd: i32) -> Result<(), Error>
pub fn send_handle(&mut self, json: &str, fd: i32) -> Result<(), Error>
Send a JSON message + fd via SCM_RIGHTS ancillary data.
The fd is duplicated into the kernel’s ancillary buffer; the receiver obtains a new independent fd via recvmsg. The kernel-level fd remains valid in the sender until the sender closes it (we do NOT close it here — the caller may still need it).
Sourcepub fn recv_msg(&mut self) -> Result<(String, Option<i32>), Error>
pub fn recv_msg(&mut self) -> Result<(String, Option<i32>), Error>
Receive the next JSON message (blocking read until a newline-terminated
line is available, or until a SCM_RIGHTS recvmsg delivers a complete
payload). Returns (json, Option<fd>) — the fd, if present, was
carried by the SCM_RIGHTS ancillary data of one of the recvmsg calls
that produced this message.
Returns an UnexpectedEof error when the peer has closed the channel
and the buffer is drained. is_connected() will return false afterwards.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true while neither side has closed the channel.
Trait Implementations§
Source§impl Drop for IpcChannel
impl Drop for IpcChannel
Auto Trait Implementations§
impl Freeze for IpcChannel
impl RefUnwindSafe for IpcChannel
impl Send for IpcChannel
impl Sync for IpcChannel
impl Unpin for IpcChannel
impl UnsafeUnpin for IpcChannel
impl UnwindSafe for IpcChannel
Blanket Implementations§
Source§impl<T> AsCtxPtr for Twhere
T: ?Sized,
impl<T> AsCtxPtr for Twhere
T: ?Sized,
Source§fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
self’s address as *mut Self for deferred-task / scopeguard /
ref_guard ctx slots. The closures/trampolines deref it as shared
(&*p) — every method they reach is &self post-R-2, so no write
provenance is required; the *mut spelling is purely to match the
existing DerefOnDrop / HasAutoFlush / RefCount ABI.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more