pub struct AsyncSocket { /* private fields */ }
Expand description
A wrapper type around Socket
to enable async-await send and receive
operations.
This type allows for getting a single future (send or receive) from a socket at a time. This is
useful for raw sockets and scalability protocols which cannot leverage
Context
, and thus need to perform send and receive operations on an owned
socket directly.
If you have set up your socket such that it can be used with contexts, it is instead
recommended to use AsyncContext
, which only needs to borrow
the underlying socket. Contexts are more useful for concurrent operations where
of futures for each independent operation on a socket.
Implementations§
Source§impl AsyncSocket
impl AsyncSocket
Sourcepub async fn send<M>(
&mut self,
msg: M,
timeout: Option<Duration>,
) -> Result<(), (Message, Error)>
pub async fn send<M>( &mut self, msg: M, timeout: Option<Duration>, ) -> Result<(), (Message, Error)>
Sends a Message
to the socket asynchronously.
§Errors
IncorrectState
if the internalAio
is already running an operation, or the socket cannot send messages in its current state.MessageTooLarge
: The message is too large.NotSupported
: The protocol does not support sending messages.OutOfMemory
: Insufficient memory available.TimedOut
: The operation timed out.
Sourcepub async fn receive(
&mut self,
timeout: Option<Duration>,
) -> Result<Message, Error>
pub async fn receive( &mut self, timeout: Option<Duration>, ) -> Result<Message, Error>
Receives a Message
from the socket asynchronously.
§Errors
IncorrectState
if the internalAio
is already running an operation, or the socket cannot send messages in its current state.MessageTooLarge
: The message is too large.NotSupported
: The protocol does not support sending messages.OutOfMemory
: Insufficient memory available.TimedOut
: The operation timed out.
Sourcepub fn into_inner(self) -> Socket
pub fn into_inner(self) -> Socket
Grabs the inner Socket
.
Trait Implementations§
Source§impl Debug for AsyncSocket
impl Debug for AsyncSocket
Auto Trait Implementations§
impl Freeze for AsyncSocket
impl RefUnwindSafe for AsyncSocket
impl Send for AsyncSocket
impl Sync for AsyncSocket
impl !Unpin for AsyncSocket
impl UnwindSafe for AsyncSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more