byteor_transport_shm/options.rs
1//! Open options for SHM regions.
2
3use std::path::PathBuf;
4
5use crate::util::default_region_path;
6
7/// Options for opening a mapped ByteOr-owned region.
8#[derive(Debug, Clone, Default)]
9pub struct OpenOptions {
10 pub(crate) path: Option<PathBuf>,
11 pub(crate) blocking: bool,
12 pub(crate) prefault: bool,
13}
14
15impl OpenOptions {
16 /// Create default open options.
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 /// Override the backing file path.
22 pub fn path(mut self, path: impl Into<PathBuf>) -> Self {
23 self.path = Some(path.into());
24 self
25 }
26
27 /// Enable an appended wake section for `SequencedSlotsLayout<N>` and set
28 /// `INDEXBUS_CAP_SUPPORTS_BLOCKING`.
29 ///
30 /// All participants opening the same backing file must agree on this flag.
31 pub fn blocking(mut self, enabled: bool) -> Self {
32 self.blocking = enabled;
33 self
34 }
35
36 /// Prefault the mapping by touching each mapped page after `mmap` succeeds.
37 ///
38 /// This is useful for low-latency runs that want to reduce first-touch page faults,
39 /// but it remains opt-in because it increases bring-up work.
40 pub fn prefault(mut self, enabled: bool) -> Self {
41 self.prefault = enabled;
42 self
43 }
44
45 pub(crate) fn resolve_path(&self, name: &str) -> PathBuf {
46 self.path
47 .clone()
48 .unwrap_or_else(|| default_region_path(name))
49 }
50}