1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! The values the transport truly owns, in one place.
//!
//! Two families live here:
//!
//! - the **protocol invariants** (`PAYLOAD_ALIGNMENT`, `enable_safe_overflow`):
//! changing one is a wire-protocol change and requires bumping
//! [`PROTOCOL_VERSION`](crate::types::consts::PROTOCOL_VERSION), so they are
//! compiled in and never exposed;
//! - the **runtime tuning** (`WAITSET_DEADLINE`, `IDLE_SPINS`, ...): invisible to
//! a peer, so a process may adjust them on its own.
//!
//! The service limits one might expect here — publishers, subscribers, nodes,
//! subscriber buffer size, slice length and loaned samples — are deliberately
//! **absent**. They are deployment policy, not implementation choices: every
//! participant inherits them from the iceoryx2 configuration it resolves. The one
//! exception is the slice length, which iceoryx2 0.10 does not expose in its
//! configuration and whose builder default is `1`; the developer declares it per
//! channel with `#[service(max_slice_len = N)]`, see [`DEFAULT_MAX_SLICE_LEN`].
//!
//! | Setting | Value | Why |
//! |---|---|---|
//! | `PAYLOAD_ALIGNMENT` | 16 | the alignment `rkyv::to_bytes` produces, so a sample decodes in place |
//! | `REQUEST_SCRATCH_CAPACITY` | 256 bytes | starting size of the per-thread request buffer; rkyv grows it when a request is larger |
//! | `enable_safe_overflow` | **false** | enabled, a full subscriber buffer silently overwrites its oldest pending sample, losing a request that is never answered; disabled, `send()` reports `0` delivered and the publisher retries, turning the overflow into backpressure |
//! | `WAITSET_DEADLINE` | 1 ms | bounds the cost of a missed notification |
//! | `IDLE_SPINS` | 2 000 yields | the hot path stays at polling speed, the idle path blocks on the `WaitSet` |
use Duration;
/// Suffixes of the iceoryx2 services backing one channel.
pub const REQUEST_SUFFIX: &str = "_req";
pub const RESPONSE_SUFFIX: &str = "_resp";
pub const REQUEST_NOTIFY_SUFFIX: &str = "_req_notify";
pub const RESPONSE_NOTIFY_SUFFIX: &str = "_resp_notify";
pub const DEFAULT_MAX_SLICE_LEN: usize = 256;
/// Payload alignment requested from iceoryx2, the alignment `rkyv::to_bytes`
/// produces, so a sample is decodable in place. It is also the alignment every
/// buffer that holds an encoded request uses, so the payload stays aligned when
/// it is written.
pub const PAYLOAD_ALIGNMENT: usize = 16;
/// Initial capacity of the per-thread request-encoding buffer, in bytes.
///
/// A starting size, not a limit: rkyv grows the buffer when a request is larger.
/// 256 covers the common small request, so the hot path allocates once per
/// **thread** instead of once per call.
pub const REQUEST_SCRATCH_CAPACITY: usize = 256;
/// How long a call waits for the provider to be connected before failing.
///
/// Overridable with `ICE_RPC_PROVIDER_WAIT_MS`.
pub const PROVIDER_WAIT_DEFAULT: Duration = from_secs;
/// How long a response waits for the consumer to be connected.
pub const CONSUMER_WAIT_TIMEOUT: Duration = from_millis;
/// Sleep between two delivery attempts, once the spin budget is exhausted.
pub const PUBLISH_RETRY_SLEEP: Duration = from_millis;
/// Consecutive delivery attempts spent yielding before the retry loop sleeps.
///
/// A full channel is the normal case of a burst; a sleep costs the system timer.
pub const PUBLISH_SPIN_ATTEMPTS: u32 = 4_096;
/// Upper bound on how long a dispatch thread blocks before it drains again.
///
/// The wait itself is event-driven; this deadline is the safety net that bounds
/// the cost of a missed notification.
pub const WAITSET_DEADLINE: Duration = from_millis;
/// Attempts made to open the ports of a channel before giving up on it.
///
/// iceoryx2 answers `SystemInFlux` when another process is creating or removing
/// that exact service at this instant — a race the next attempt wins. Without a
/// retry, one such blip left the channel dead for the rest of the process
/// lifetime, although the error is classified as retryable.
pub const OPEN_RETRY_ATTEMPTS: u32 = 20;
/// Delay between two attempts at opening the ports of a channel.
///
/// 20 × 50 ms is a one-second budget: wider than a process teardown, and the
/// price is paid only by a channel that recovers. A non-retryable failure (a
/// service left by another build) returns immediately instead of waiting.
pub const OPEN_RETRY_SLEEP: Duration = from_millis;
/// Processed samples between two termination checks on the busy path.
///
/// `SignalHandler::termination_requested()` takes a process-wide mutex.
pub const SIGNAL_CHECK_SAMPLES: u32 = 256;
/// Consecutive empty polls spent spinning before a thread blocks on its
/// `WaitSet`.
pub const IDLE_SPINS: u32 = 2_000;