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
124
125
126
127
128
use super::QueueLimit;
use crate::error::NetError;
use crate::Result;
/// Capacity and receive policy for one message subscription or initial inbox.
#[derive(Clone, Debug)]
pub struct ReceiveOptions {
/// Maximum queued messages (256 by default).
pub max_messages: usize,
/// Maximum total payload bytes (64 MiB by default).
pub max_bytes: usize,
/// Policy used when a message cannot enter the queue.
pub overflow: ReceiveOverflow,
/// Whether Ping, Pong, and Close frames are delivered (default `false`).
pub include_control_frames: bool,
}
impl Default for ReceiveOptions {
fn default() -> Self {
Self {
max_messages: 256,
max_bytes: 64 * 1024 * 1024,
overflow: ReceiveOverflow::Disconnect,
include_control_frames: false,
}
}
}
impl ReceiveOptions {
/// Validates queue item and byte limits.
pub fn validate(&self) -> Result<()> {
QueueLimit {
max_items: self.max_messages,
max_bytes: self.max_bytes,
}
.validate_fields("receive.max_messages", "receive.max_bytes")
}
}
/// Behavior when a message subscription reaches capacity.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ReceiveOverflow {
/// Report overflow and disconnect the current connection.
Disconnect,
/// Drop the oldest queued message to make room for the new one.
DropOldest,
}
/// Capacity for connection-event history or one event subscription.
#[derive(Clone, Debug)]
pub struct EventOptions {
/// Maximum retained events (32 by default).
pub max_events: usize,
/// Maximum accounted bytes (1 MiB by default).
pub max_bytes: usize,
}
impl Default for EventOptions {
fn default() -> Self {
Self {
max_events: 32,
max_bytes: 1024 * 1024,
}
}
}
impl EventOptions {
/// Validates event count and byte limits.
pub fn validate(&self) -> Result<()> {
QueueLimit {
max_items: self.max_events,
max_bytes: self.max_bytes,
}
.validate_fields("events.max_events", "events.max_bytes")
}
}
/// Reserved capacity for one terminal task-event subscription.
#[derive(Clone, Debug)]
pub struct TaskEventOptions {
/// Maximum reserved terminal notifications (1024 by default).
pub max_tasks: usize,
/// Maximum total bytes for associated payloads (16 MiB by default).
pub max_payload_bytes: usize,
/// Capacity reserved for the urgent lane; `None` shares all capacity between lanes.
/// When set, positive item and byte capacity must remain for normal tasks.
pub urgent_reserve: Option<QueueLimit>,
}
impl Default for TaskEventOptions {
fn default() -> Self {
Self {
max_tasks: 1024,
max_payload_bytes: 16 * 1024 * 1024,
urgent_reserve: None,
}
}
}
impl TaskEventOptions {
/// Validates total capacity and urgent-lane reservations.
pub fn validate(&self) -> Result<()> {
QueueLimit {
max_items: self.max_tasks,
max_bytes: self.max_payload_bytes,
}
.validate_fields("task_events.max_tasks", "task_events.max_payload_bytes")?;
if let Some(urgent) = &self.urgent_reserve {
urgent.validate_fields(
"task_events.urgent_reserve.max_items",
"task_events.urgent_reserve.max_bytes",
)?;
if urgent.max_items >= self.max_tasks {
return Err(NetError::config(
"task_events.urgent_reserve.max_items",
"must leave positive capacity for normal tasks within max_tasks",
));
}
if urgent.max_bytes >= self.max_payload_bytes {
return Err(NetError::config(
"task_events.urgent_reserve.max_bytes",
"must leave positive capacity for normal tasks within max_payload_bytes",
));
}
}
Ok(())
}
}