Skip to main content

Sender

Struct Sender 

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

Source

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.

Trait Implementations§

Source§

impl<W: Write> Clone for Sender<W>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<W: Write> Debug for Sender<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Shows the session label and whether the session still accepts sends.

Auto Trait Implementations§

§

impl<W> Freeze for Sender<W>
where Weak<Outbound<W>>: Freeze,

§

impl<W> RefUnwindSafe for Sender<W>
where Weak<Outbound<W>>: RefUnwindSafe,

§

impl<W> Send for Sender<W>
where Weak<Outbound<W>>: Send,

§

impl<W> Sync for Sender<W>
where Weak<Outbound<W>>: Sync,

§

impl<W> Unpin for Sender<W>
where Weak<Outbound<W>>: Unpin,

§

impl<W> UnsafeUnpin for Sender<W>
where Weak<Outbound<W>>: UnsafeUnpin,

§

impl<W> UnwindSafe for Sender<W>
where Weak<Outbound<W>>: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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