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
//! General configuration methods for `WireframeApp`.
use tokio::sync::mpsc;
use super::WireframeApp;
use crate::{
app::{
MemoryBudgets,
Packet,
builder_defaults::{MAX_READ_TIMEOUT_MS, MIN_READ_TIMEOUT_MS, default_fragmentation},
},
codec::FrameCodec,
fragment::FragmentationConfig,
serializer::Serializer,
};
impl<S, C, E, F> WireframeApp<S, C, E, F>
where
S: Serializer + Send + Sync,
C: Send + 'static,
E: Packet,
F: FrameCodec,
{
/// Configure the read timeout in milliseconds.
/// Clamped between 1 and 86,400,000 milliseconds (24 h).
#[must_use]
pub fn read_timeout_ms(mut self, timeout_ms: u64) -> Self {
self.read_timeout_ms = timeout_ms.clamp(MIN_READ_TIMEOUT_MS, MAX_READ_TIMEOUT_MS);
self
}
/// Override the fragmentation configuration.
///
/// Provide `None` to disable fragmentation entirely.
#[must_use]
pub fn fragmentation(mut self, config: Option<FragmentationConfig>) -> Self {
self.fragmentation = config;
self
}
/// Configure per-connection memory budgets for inbound buffering.
///
/// These budgets apply across the shared inbound assembly pipeline,
/// including protocol-level message assembly and streaming request
/// hand-off state. Wireframe uses them for per-frame rejection,
/// soft-pressure read pacing, and hard-cap connection aborts.
#[must_use]
pub fn memory_budgets(mut self, budgets: MemoryBudgets) -> Self {
self.memory_budgets = Some(budgets);
self
}
/// Enable transport fragmentation using codec-derived defaults.
///
/// The derived settings are bounded by the current frame codec budget.
/// Call this after `with_codec` or `buffer_capacity` so defaults align with
/// the final frame length.
#[must_use]
pub fn enable_fragmentation(mut self) -> Self {
self.fragmentation = default_fragmentation(self.codec.max_frame_length());
self
}
/// Configure a Dead Letter Queue for dropped push frames.
///
/// ```rust,no_run
/// use tokio::sync::mpsc;
/// use wireframe::app::WireframeApp;
///
/// # fn build() -> WireframeApp {
/// # WireframeApp::new().expect("builder creation should not fail")
/// # }
/// # fn main() {
/// let (tx, _rx) = mpsc::channel(16);
/// let app = build().with_push_dlq(tx);
/// # let _ = app;
/// # }
/// ```
#[must_use]
pub fn with_push_dlq(self, dlq: mpsc::Sender<Vec<u8>>) -> Self {
WireframeApp {
push_dlq: Some(dlq),
..self
}
}
}