Struct de_net::protocol::ProtocolSocket
source · pub(crate) struct ProtocolSocket {
socket: Arc<Socket>,
}
Expand description
A thin layer over a UDP socket translating between UDP datagrams and header-payload pairs.
Fields§
§socket: Arc<Socket>
Implementations§
source§impl ProtocolSocket
impl ProtocolSocket
pub(crate) fn new(socket: Socket) -> Self
sourcepub(crate) async fn send(
&self,
header: DatagramHeader,
buf: &mut [u8],
target: SocketAddr
) -> Result<(), SendError>
pub(crate) async fn send( &self, header: DatagramHeader, buf: &mut [u8], target: SocketAddr ) -> Result<(), SendError>
Send data to a list of targets.
The sending is done in parallel.
§Arguments
-
buf
- buffer used for datagram construction. FirstHEADER_SIZE
bytes are overwritten with the header. Payload bytes must follow. -
header
- header of the datagram. -
data
- datagram payload. -
target
- recipient of the datagram.
sourcepub(crate) async fn recv<'a>(
&self,
buf: &'a mut [u8]
) -> Result<(SocketAddr, DatagramHeader, &'a [u8]), MsgRecvError>
pub(crate) async fn recv<'a>( &self, buf: &'a mut [u8] ) -> Result<(SocketAddr, DatagramHeader, &'a [u8]), MsgRecvError>
Receive a single datagram.
§Arguments
buf
- the data is written to this buffer. The buffer must be at leastMAX_DATAGRAM_SIZE
long.
§Returns
Return source address, datagram header and a slice with the payload. Header data are not included in the payload slice.
§Panics
Panics if len of buf
is smaller than MAX_DATAGRAM_SIZE
.
Trait Implementations§
source§impl Clone for ProtocolSocket
impl Clone for ProtocolSocket
source§fn clone(&self) -> ProtocolSocket
fn clone(&self) -> ProtocolSocket
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ProtocolSocket
impl RefUnwindSafe for ProtocolSocket
impl Send for ProtocolSocket
impl Sync for ProtocolSocket
impl Unpin for ProtocolSocket
impl UnwindSafe for ProtocolSocket
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