Skip to main content

Socket

Struct Socket 

Source
pub struct Socket(/* private fields */);
Expand description

Shared socket returned by socket_init. Use send_message() to send messages and message_handler() to handle incoming messages.

Implementations§

Source§

impl Socket

Source

pub async fn send_message(&self, msg: &[u8]) -> Result<(), SocketError>

Sends one message. Fails if the message length exceeds the maximum allowed size.

For local transports (named pipe, Unix domain socket): after writing the message and signaling the “data ready” event/semaphore, the call waits up to 5 seconds for the recipient to signal “data acked” (named event on Windows, named semaphore on Linux). If no acknowledgment is received in time, returns Err(SocketError::RecipientAckTimeout). The recipient (e.g. message_handler callback or an external process) must signal the “data acked” event/semaphore after each successful read so the sender can complete.

On Windows the data-ready event is Global\<pipe_name>.data_ready; the ack event is Global\<pipe_name>.data_acked. On Linux the semaphores are /ipcez_<path>_data_ready and /ipcez_<path>_data_acked.

For WebSocket (remote), no ack wait is performed; the call returns after write and flush.

Source

pub async fn disconnect(&self)

Closes the connection. The underlying transport is dropped. Subsequent send_message() calls and the message_handler callback will see a connection-lost error.

Source

pub fn message_handler<F, Fut>(&self, callback: F)
where F: FnMut(Result<Vec<u8>, SocketError>) -> Fut + Send + 'static, Fut: Future<Output = ()> + Send,

Spawns a task that reads incoming messages and invokes callback for each. The task runs until the connection fails or is closed. The callback receives Ok(msg) for each message and Err(e) when the connection fails or closes (then the task stops).

Auto Trait Implementations§

§

impl Freeze for Socket

§

impl !RefUnwindSafe for Socket

§

impl Send for Socket

§

impl Sync for Socket

§

impl Unpin for Socket

§

impl !UnwindSafe for Socket

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