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
impl Socket
Sourcepub async fn send_message(&self, msg: &[u8]) -> Result<(), SocketError>
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.
Sourcepub async fn disconnect(&self)
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.
Sourcepub fn message_handler<F, Fut>(&self, callback: F)
pub fn message_handler<F, Fut>(&self, callback: F)
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).