tokio_vsock/
tonic_support.rs

1use crate::VsockAddr;
2
3/// Connection info for a Vsock Stream.
4///
5/// See [`Connected`][tonic012::transport::server::Connected] for more details.
6///
7#[derive(Debug, Clone, Eq, PartialEq)]
8pub struct VsockConnectInfo {
9    peer_addr: Option<VsockAddr>,
10}
11
12impl VsockConnectInfo {
13    /// Return the remote address the IO resource is connected too.
14    pub fn peer_addr(&self) -> Option<VsockAddr> {
15        self.peer_addr
16    }
17}
18
19macro_rules! tonic_connected {
20    ($tonic_version:ident $cfg:literal) => {
21        /// Allow consumers of VsockStream to check that it is connected and valid before use.
22        ///
23        #[cfg(feature = $cfg)]
24        #[cfg_attr(docsrs, doc(cfg(feature = $cfg)))]
25        impl $tonic_version::transport::server::Connected for crate::VsockStream {
26            type ConnectInfo = VsockConnectInfo;
27
28            fn connect_info(&self) -> Self::ConnectInfo {
29                VsockConnectInfo {
30                    peer_addr: self.peer_addr().ok(),
31                }
32            }
33        }
34    };
35}
36
37tonic_connected!(tonic05 "tonic05");
38tonic_connected!(tonic06 "tonic06");
39tonic_connected!(tonic07 "tonic07");
40tonic_connected!(tonic08 "tonic08");
41tonic_connected!(tonic09 "tonic09");
42tonic_connected!(tonic010 "tonic010");
43tonic_connected!(tonic011 "tonic011");
44tonic_connected!(tonic012 "tonic012");
45tonic_connected!(tonic013 "tonic013");