pub struct Sender<W: Write> { /* private fields */ }Expand description
Cloneable handle for sending messages into a session from any thread.
Returned by Client::connect or delivered in a
server’s Connected event.
Sends share one encryption sequence and are written in that order. Each send waits for its own frame and receives its own result. A handle belongs permanently to the session that issued it. Session failure, disconnect, reconnect or dropping the client/server invalidates all that session’s handles. A new session supplies a new sender. Old handles cannot send into it.
The client/server retains the session and stream. Idle senders hold only weak references and do not extend either lifetime. An active send temporarily retains both, but can write only while its session remains current. Dropping a sender does not end the session.
Implementations§
Source§impl<W: Write> Sender<W>
impl<W: Write> Sender<W>
Sourcepub fn send(&self, message: &[u8]) -> Result<(), Error>
pub fn send(&self, message: &[u8]) -> Result<(), Error>
Encrypts a message, writes its complete frame and flushes the output. Concurrent sends preserve encryption order on the wire. The next message can be encrypted while the previous one is being written. An oversized message is refused without advancing encryption or ending the session.
The write timeout starts after acquiring the writer. Frame encoding, recovery delimiters, partial writes and flush all share that budget. Encryption and waiting for the writer are outside the budget.
An output failure ends the session before returning. Subsequent sends and
receive completions are refused. A timeout returns Error::SendFailed
containing an I/O TimedOut error and leaves the byte stream reusable.
Server failure notification uses the frame’s remaining budget and is
skipped after timeout. Ending this way does not wake a blocked receive.
Ending from another thread waits for a send holding the writer lock. Queued sends can still encrypt, but must belong to the current session when they acquire the writer.
Returns Error::Terminated if the outgoing transport was released.
Returns Error::EncryptionFailed if the context was released or its
session ended. Permanent stream closure is observed through I/O, so an
overlapping send may succeed. Unexpected encryption failures and poisoned
locks panic. Transport reuse after a panic is unsupported.