netlink_sys/async_socket.rs
1// SPDX-License-Identifier: MIT
2
3use std::{
4 io,
5 task::{Context, Poll},
6};
7
8use crate::{Socket, SocketAddr};
9
10/// Trait to support different async backends
11pub trait AsyncSocket: Sized + Unpin {
12 /// Access underyling [`Socket`]
13 fn socket_ref(&self) -> &Socket;
14
15 /// Mutable access to underyling [`Socket`]
16 fn socket_mut(&mut self) -> &mut Socket;
17
18 /// Wrapper for [`Socket::new`]
19 fn new(protocol: isize) -> io::Result<Self>;
20
21 /// Polling wrapper for [`Socket::send`]
22 fn poll_send(
23 &mut self,
24 cx: &mut Context<'_>,
25 buf: &[u8],
26 ) -> Poll<io::Result<usize>>;
27
28 /// Polling wrapper for [`Socket::send_to`]
29 fn poll_send_to(
30 &mut self,
31 cx: &mut Context<'_>,
32 buf: &[u8],
33 addr: &SocketAddr,
34 ) -> Poll<io::Result<usize>>;
35
36 /// Polling wrapper for [`Socket::recv`]
37 ///
38 /// Passes 0 for flags, and ignores the returned length (the buffer will
39 /// have advanced by the amount read).
40 fn poll_recv<B>(
41 &mut self,
42 cx: &mut Context<'_>,
43 buf: &mut B,
44 ) -> Poll<io::Result<()>>
45 where
46 B: bytes::BufMut;
47
48 /// Polling wrapper for [`Socket::recv_from`]
49 ///
50 /// Passes 0 for flags, and ignores the returned length - just returns the
51 /// address (the buffer will have advanced by the amount read).
52 fn poll_recv_from<B>(
53 &mut self,
54 cx: &mut Context<'_>,
55 buf: &mut B,
56 ) -> Poll<io::Result<SocketAddr>>
57 where
58 B: bytes::BufMut;
59
60 /// Polling wrapper for [`Socket::recv_from_full`]
61 ///
62 /// Passes 0 for flags, and ignores the returned length - just returns the
63 /// address (the buffer will have advanced by the amount read).
64 fn poll_recv_from_full(
65 &mut self,
66 cx: &mut Context<'_>,
67 ) -> Poll<io::Result<(Vec<u8>, SocketAddr)>>;
68}