Struct turbulence::unreliable_channel::UnreliableChannel
source · [−]pub struct UnreliableChannel<R, P> where
R: Runtime,
P: PacketPool, { /* private fields */ }
Expand description
Turns a stream of unreliable, unordered packets into a stream of unreliable, unordered messages.
Implementations
sourceimpl<R, P> UnreliableChannel<R, P> where
R: Runtime,
P: PacketPool,
impl<R, P> UnreliableChannel<R, P> where
R: Runtime,
P: PacketPool,
pub fn new(
runtime: R,
packet_pool: P,
settings: Settings,
incoming: Receiver<P::Packet>,
outgoing: Sender<P::Packet>
) -> Self
sourcepub async fn send(&mut self, msg: &[u8]) -> Result<(), SendError>
pub async fn send(&mut self, msg: &[u8]) -> Result<(), SendError>
Write the given message to the channel.
Messages are coalesced into larger packets before being sent, so in order to guarantee that
the message is actually sent, you must call flush
.
Messages have a maximum size based on the size of the packets returned from the packet pool.
Two bytes are used to encode the length of the message, so the maximum message length is
packet.len() - 2
, for whatever packet sizes are returned by the pool.
This method is cancel safe, it will never partially send a message, though canceling it may or may not buffer a message to be sent.
sourcepub async fn flush(&mut self) -> Result<(), SendError>
pub async fn flush(&mut self) -> Result<(), SendError>
Finish sending any unsent coalesced packets.
This must be called to guarantee that any sent messages are actually sent to the outgoing packet stream.
This method is cancel safe.
sourcepub async fn recv(&mut self) -> Result<&[u8], RecvError>
pub async fn recv(&mut self) -> Result<&[u8], RecvError>
Receive a message into the provide buffer.
If the received message fits into the provided buffer, this will return Ok(message_len)
,
otherwise it will return Err(RecvError::TooBig)
.
This method is cancel safe, it will never partially read a message or drop received messages.
Auto Trait Implementations
impl<R, P> !RefUnwindSafe for UnreliableChannel<R, P>
impl<R, P> Send for UnreliableChannel<R, P> where
P: Send,
<P as PacketPool>::Packet: Send,
impl<R, P> Sync for UnreliableChannel<R, P> where
P: Sync,
<P as PacketPool>::Packet: Send + Sync,
impl<R, P> Unpin for UnreliableChannel<R, P> where
P: Unpin,
<P as PacketPool>::Packet: Unpin,
impl<R, P> !UnwindSafe for UnreliableChannel<R, P>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more