Skip to main content

SocketClient

Struct SocketClient 

Source
pub struct SocketClient {
    pub session_id: SessionId,
    /* private fields */
}
Expand description

A client connection to the kernel’s Unix-domain socket.

Fields§

§session_id: SessionId

The unique identifier for this session.

Implementations§

Source§

impl SocketClient

Source

pub async fn connect(session_id: SessionId) -> Result<Self>

Connect to an existing session socket and perform the authenticated handshake.

§Errors

Returns an error if the socket file does not exist, connection fails, or the handshake is rejected.

Source

pub async fn read_message(&mut self) -> Result<Option<IpcMessage>>

Read the next IPC message from the daemon.

Frames that don’t deserialize cleanly as IpcMessage (notably the kernel’s astrid.v1.capsules_loaded broadcast, whose IpcPayload::RawJson inner value is emitted without the type discriminator) are logged at debug and skipped. Without this tolerance interactive clients would die on the first broadcast.

§Errors

Returns an error if the connection is unrecoverable (over-large frame, IO failure mid-read).

Source

pub async fn read_raw_frame(&mut self) -> Result<Option<Vec<u8>>>

Read the next length-prefixed frame as raw bytes, without attempting to deserialize. Used by crate::admin_client when it needs to tolerate broadcast messages that don’t deserialize cleanly into IpcMessage.

§Errors

Returns an error if the frame cannot be read.

Source

pub async fn read_until_topic( &mut self, want_topic: &str, timeout: Duration, ) -> Result<Value>

Read frames until one arrives on want_topic or timeout elapses. Frames that fail to deserialize as JSON or carry a different topic are silently skipped.

§Errors

Returns an error if the deadline elapses, the connection closes, or a read fails.

Source

pub fn extract_kernel_response(raw: &Value) -> Option<KernelResponse>

Extract the inner kernel response from a raw frame previously returned by read_until_topic.

The kernel emits one of two on-wire shapes depending on which router branch produced the response:

  • Bare typed payload — { "type": "...", ... }, already a KernelResponse-shaped object that serde_json::from_value can deserialize directly.
  • RawJson-wrapped payload — { "type": "raw_json", "value": { "type": "...", ... } } (the older router branch wraps the typed body in IpcPayload::RawJson).

Both have to be tolerated by every consumer of the bare verbs. Returns None when the frame has no payload field or the deserialization fails — callers fall back to an empty display rather than crashing.

Source

pub async fn send_input( &mut self, text: String, caller: &PrincipalId, ) -> Result<()>

Send a user-prompt message on behalf of caller.

Convenience helper for chat-style uplinks. Stamps IpcMessage.principal from the caller so the kernel’s resolve_caller sees the right principal for session, KV, home, secret, and quota scoping.

§Errors

Returns an error if the message cannot be sent.

Source

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

Send a raw IPC message to the kernel.

The caller is responsible for stamping IpcMessage::principal before calling — this transport does not infer it.

§Errors

Returns an error if the message cannot be serialized or sent.

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, 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