Skip to main content

BackendHandle

Struct BackendHandle 

Source
pub struct BackendHandle {
    pub service_name: String,
    pub service_version: String,
    pub daemon_process: DaemonProcess,
    /* private fields */
}
Expand description

A verified handle to a running backend daemon.

The handle carries the daemon identity needed to defend against stale manifests and PID recycling before consumers connect to the IPC endpoint.

A handle is created only through one of the probe* constructors. The constructor performs all identity checks first; successful callers may then use Self::is_alive for a cheap liveness check or Self::connect to open a fresh local-socket connection.

Fields§

§service_name: String

Logical service name from the manifest or direct probe caller.

§service_version: String

Service version from the manifest or direct probe caller.

§daemon_process: DaemonProcess

Verified daemon process identity.

Implementations§

Source§

impl BackendHandle

Source

pub fn probe(endpoint: &Endpoint, expected: &DaemonProcess) -> Option<Self>

Connect to an existing backend by endpoint and verify process identity.

This probe verifies the endpoint identity tuple, requires the endpoint to answer the nonce-based IPC identity probe, then verifies current boot ID, process liveness, executable path, and executable SHA-256. It returns None for stale manifests, dead PIDs, mismatched daemon binaries, or endpoints that do not answer as the expected backend.

Use this when the caller already has service metadata elsewhere and only needs to know whether the daemon identity is still valid.

BLOCKING. Performs synchronous IPC up to probe::DEFAULT_ENDPOINT_PROBE_TIMEOUT (500 ms). From a tokio task, call from spawn_blocking or switch to [Self::probe_async] (requires the client-async feature).

use running_process::broker::backend_handle::{BackendHandle, DaemonProcess};
use running_process::broker::protocol::Endpoint;

if let Some(handle) = BackendHandle::probe(&endpoint, &expected) {
    assert!(handle.is_alive());
}
Source

pub fn probe_with_service( service_name: impl Into<String>, service_version: impl Into<String>, endpoint: &Endpoint, expected: &DaemonProcess, ) -> Result<Self>

Probe an existing backend and attach service metadata to the handle.

This is the preferred constructor for direct-daemon consumers because it preserves the logical service tuple alongside the verified process identity.

BLOCKING. Performs synchronous IPC up to probe::DEFAULT_ENDPOINT_PROBE_TIMEOUT (500 ms). From a tokio task, call from spawn_blocking or use [Self::probe_with_service_async] (requires the client-async feature) instead — calling this directly from an async context will block the runtime worker thread.

use running_process::broker::backend_handle::{BackendHandle, DaemonProcess};
use running_process::broker::protocol::Endpoint;

BackendHandle::probe_with_service("zccache", "0.8.0", &endpoint, &expected)
Source

pub fn probe_manifest(manifest: &CacheManifest) -> Option<Self>

Probe the current_daemon recorded in a cache manifest.

Returns None when the manifest has no daemon entry or when the daemon entry no longer matches a live process on the current boot.

use running_process::broker::backend_handle::BackendHandle;
use running_process::broker::protocol::CacheManifest;

match BackendHandle::probe_manifest(manifest) {
    Some(handle) if handle.is_alive() => {
        // Reuse the verified backend.
    }
    _ => {
        // Spawn or discover a replacement backend.
    }
}
Source

pub fn try_from_manifest(manifest: &CacheManifest) -> Result<Option<Self>>

Fallible variant of Self::probe_manifest that preserves parse errors.

Use this in maintenance tools and diagnostics where malformed manifest identities should be reported separately from a normal cache miss.

Source

pub fn is_alive(&self) -> bool

Check liveness without opening a new IPC connection.

On platforms with an owned process-handle primitive, this checks the handle captured during probing. Otherwise it falls back to opening the process ID again.

Source

pub async fn connect(&self) -> Result<Connection>

Open a fresh IPC connection to this backend.

The process identity is verified when the handle is created. Callers that cache handles for a long time should call Self::is_alive or reprobe from the latest manifest before opening a connection.

use running_process::broker::backend_handle::BackendHandle;

async fn connect_to_verified_backend(
    handle: &BackendHandle,
) -> running_process::broker::backend_handle::Result<()> {
    let connection = handle.connect().await?;
    let _stream = connection.into_inner();
    Ok(())
}
Source

pub async fn shutdown(self, timeout: Duration) -> Result<()>

Send a graceful shutdown signal and wait until the process exits.

On Windows this foundation returns GracefulTerminateUnsupported until the broker shutdown request protocol lands.

Dropping the handle without calling this method leaves the backend running.

Source

pub fn force_kill(self) -> Result<()>

Force-kill the daemon process.

This is the last-resort teardown path for a daemon that ignored graceful shutdown or whose IPC protocol is unavailable.

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> 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.