zenoh_link_unixsock_stream/
lib.rs1use std::str::FromStr;
21
22use async_trait::async_trait;
23use zenoh_core::zconfigurable;
24use zenoh_link_commons::LocatorInspector;
25use zenoh_protocol::core::{endpoint::Address, Locator, Metadata, Reliability};
26#[cfg(target_family = "unix")]
27use zenoh_protocol::transport::BatchSize;
28use zenoh_result::ZResult;
29
30#[cfg(target_family = "unix")]
31mod unicast;
32#[cfg(target_family = "unix")]
33pub use unicast::*;
34
35#[cfg(target_family = "unix")]
42const UNIXSOCKSTREAM_MAX_MTU: BatchSize = BatchSize::MAX;
43
44pub const UNIXSOCKSTREAM_LOCATOR_PREFIX: &str = "unixsock-stream";
45
46const IS_RELIABLE: bool = true;
47
48zconfigurable! {
49 #[cfg(target_family = "unix")]
51 static ref UNIXSOCKSTREAM_DEFAULT_MTU: BatchSize = UNIXSOCKSTREAM_MAX_MTU;
52 #[cfg(target_family = "unix")]
55 static ref UNIXSOCKSTREAM_ACCEPT_THROTTLE_TIME: u64 = 100_000;
56}
57
58#[derive(Default, Clone, Copy)]
59pub struct UnixSockStreamLocatorInspector;
60#[async_trait]
61impl LocatorInspector for UnixSockStreamLocatorInspector {
62 fn protocol(&self) -> &str {
63 UNIXSOCKSTREAM_LOCATOR_PREFIX
64 }
65
66 async fn is_multicast(&self, _locator: &Locator) -> ZResult<bool> {
67 Ok(false)
68 }
69
70 fn is_reliable(&self, locator: &Locator) -> ZResult<bool> {
71 if let Some(reliability) = locator
72 .metadata()
73 .get(Metadata::RELIABILITY)
74 .map(Reliability::from_str)
75 .transpose()?
76 {
77 Ok(reliability == Reliability::Reliable)
78 } else {
79 Ok(IS_RELIABLE)
80 }
81 }
82}
83
84pub fn get_unix_path_as_string(address: Address<'_>) -> String {
85 address.to_string()
86}