pub struct Sender { /* private fields */ }
Expand description

A struct to handle sending unreliable datagrams.

The Sender struct contains the queue of unreliable datagrams to be sent. During transmission time, we alternate between sending datagrams and sending stream data. This is to ensure there is a balance between the amount of reliable and unreliable data getting sent.

Datagrams are written to the packet in the order they are added to the queue. A datagram that is too large to fit in the packet will be dropped, unless the packet already contains written datagrams. This attempts to prevent the case where all datagrams are dropped because only a small amount of packet space remains.

Note that there is currently no expiration date for datagrams to live on the queue. Implement the Sender trait if this behavior is necessary for your use-case.

Implementations§

source§

impl Sender

source

pub fn poll_send_datagram( &mut self, data: &mut Bytes, cx: &mut Context<'_> ) -> Poll<Result<(), DatagramError>>

Enqueues a datagram for sending it towards the peer.

§Return value
  • Poll::Pending if the datagram’s send buffer capacity is currently exhausted and the datagram was not added to the queue. In this case, the caller should retry sending after the Waker on the provided Context is notified.
  • Poll::Ready(Ok(())) if the datagram was enqueued for sending.
  • Poll::Ready(Err(DatagramError)) if an error occurred while trying to send the datagram.
source

pub fn send_datagram_forced( &mut self, data: Bytes ) -> Result<Option<Bytes>, DatagramError>

Adds datagrams on the queue to be sent

If the datagram queue is at capacity the oldest datagram will be popped off the queue and returned to make space for the newest datagram.

§Return value
  • Ok(None) if the datagram was enqueued for sending
  • Ok(Some(Bytes)) if the queue is at capacity this will be the oldest datagram on the queue
  • Err(DatagramError) if some error occurred
source

pub fn send_datagram(&mut self, data: Bytes) -> Result<(), DatagramError>

Adds datagrams on the queue to be sent

If the queue is full the newest datagram is not added and an error is returned.

§Return value
  • Ok() if the datagram was enqueued for sending
  • Err(DatagramError) if some error occurred
source

pub fn retain_datagrams<F>(&mut self, f: F)
where F: FnMut(&Datagram) -> bool,

Filter through the datagrams in the send queue and only keep those that match a predicate

source

pub fn max_packet_space(&self) -> usize

Returns the largest packet space for datagrams seen during this connection.

Should be used to determine an appropriate datagram size that can be sent in this connection.

source

pub fn min_packet_space(&self) -> usize

Returns the smallest packet space for datagrams seen during this connection.

Should be used to determine an appropriate datagram size that can be sent in this connection.

source

pub fn smoothed_packet_space(&self) -> usize

Returns a smoothed calculation of the size of packet space for datagrams seen during this connection.

Should be used to determine an appropriate datagram size that can be sent in this connection.

Trait Implementations§

source§

impl Debug for Sender

source§

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

Formats the value using the given formatter. Read more
source§

impl Sender for Sender

source§

fn on_transmit<P: Packet>(&mut self, packet: &mut P)

A callback that allows users to write datagrams directly to the packet
source§

fn has_transmission_interest(&self) -> bool

A callback that checks if a user has datagrams ready to send Read more
source§

fn on_connection_error(&mut self, error: Error)

A callback used to notify the application in the case of a connection error

Auto Trait Implementations§

§

impl Freeze for Sender

§

impl RefUnwindSafe for Sender

§

impl Send for Sender

§

impl Sync for Sender

§

impl Unpin for Sender

§

impl UnwindSafe for Sender

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

source§

fn upcast(self) -> T

source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

source§

fn upcast_from(value: Counter<T, B>) -> T