rwebtransport 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +153 -226
- package/Cargo.toml +5 -5
- package/README.md +4 -4
- package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
- package/crates/native/Cargo.toml +1 -1
- package/crates/native/src/config.rs +13 -1
- package/crates/native/src/driver.rs +249 -91
- package/crates/native/src/lib.rs +9 -10
- package/crates/native/src/parser_memory.rs +1 -0
- package/crates/native/src/server.rs +197 -182
- package/crates/native/src/session.rs +329 -177
- package/crates/native/src/test_support.rs +2 -2
- package/crates/wtcore/src/h3.rs +166 -10
- package/dist/index.js +92 -45
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +92 -45
- package/dist/index.mjs.map +2 -2
- package/dist/native.d.ts +9 -4
- package/package.json +14 -11
- package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-x64/rwebtransport.node +0 -0
- package/prebuilds/win32-x64/rwebtransport.node +0 -0
- package/scripts/build-linux-prebuilt.sh +46 -0
- package/scripts/build.js +10 -3
- package/vendor/quiche/AGENTS.md +10 -0
- package/vendor/quiche/Cargo.lock +239 -248
- package/vendor/quiche/Cargo.toml +23 -10
- package/vendor/quiche/examples/Makefile +4 -4
- package/vendor/quiche/examples/client.rs +10 -28
- package/vendor/quiche/examples/http3-client.rs +20 -34
- package/vendor/quiche/examples/http3-server.rs +47 -78
- package/vendor/quiche/examples/server.rs +19 -49
- package/vendor/quiche/include/quiche.h +35 -4
- package/vendor/quiche/src/build.rs +17 -0
- package/vendor/quiche/src/cid.rs +129 -61
- package/vendor/quiche/src/crypto/boringssl.rs +98 -86
- package/vendor/quiche/src/crypto/mod.rs +64 -77
- package/vendor/quiche/src/dgram.rs +2 -3
- package/vendor/quiche/src/error.rs +22 -20
- package/vendor/quiche/src/ffi.rs +558 -280
- package/vendor/quiche/src/flowcontrol.rs +0 -7
- package/vendor/quiche/src/frame.rs +134 -135
- package/vendor/quiche/src/h3/ffi.rs +73 -60
- package/vendor/quiche/src/h3/frame.rs +70 -90
- package/vendor/quiche/src/h3/mod.rs +1024 -593
- package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
- package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
- package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
- package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
- package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
- package/vendor/quiche/src/h3/stream.rs +1009 -194
- package/vendor/quiche/src/lib.rs +1346 -1195
- package/vendor/quiche/src/minmax.rs +2 -6
- package/vendor/quiche/src/packet.rs +420 -552
- package/vendor/quiche/src/path.rs +202 -72
- package/vendor/quiche/src/pmtud.rs +18 -16
- package/vendor/quiche/src/ranges.rs +184 -82
- package/vendor/quiche/src/recovery/AGENTS.md +5 -2
- package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
- package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
- package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
- package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
- package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
- package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
- package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
- package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
- package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
- package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
- package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
- package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
- package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
- package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
- package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
- package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
- package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
- package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
- package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
- package/vendor/quiche/src/recovery/mod.rs +414 -173
- package/vendor/quiche/src/recovery/rtt.rs +8 -5
- package/vendor/quiche/src/stream/mod.rs +864 -133
- package/vendor/quiche/src/stream/recv_buf.rs +471 -172
- package/vendor/quiche/src/stream/send_buf.rs +338 -81
- package/vendor/quiche/src/test_utils.rs +78 -64
- package/vendor/quiche/src/tests.rs +2559 -1335
- package/vendor/quiche/src/tls/boringssl.rs +60 -63
- package/vendor/quiche/src/tls/mod.rs +146 -193
- package/vendor/quiche/src/transport_params.rs +87 -103
|
@@ -28,6 +28,8 @@ use std::cmp;
|
|
|
28
28
|
|
|
29
29
|
use std::collections::BTreeMap;
|
|
30
30
|
use std::collections::VecDeque;
|
|
31
|
+
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
32
|
+
use std::sync::Arc;
|
|
31
33
|
|
|
32
34
|
use std::time::Duration;
|
|
33
35
|
use std::time::Instant;
|
|
@@ -41,6 +43,48 @@ use crate::flowcontrol;
|
|
|
41
43
|
|
|
42
44
|
use crate::range_buf::RangeBuf;
|
|
43
45
|
|
|
46
|
+
/// Allocation budget shared by every stream on a connection, optionally with
|
|
47
|
+
/// a parent budget shared by the listener.
|
|
48
|
+
#[derive(Debug)]
|
|
49
|
+
pub(crate) struct ReceiveMemory {
|
|
50
|
+
limit: usize,
|
|
51
|
+
used: AtomicUsize,
|
|
52
|
+
parent: Option<Arc<Self>>,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
impl ReceiveMemory {
|
|
56
|
+
pub(crate) fn new(limit: usize, parent: Option<Arc<Self>>) -> Arc<Self> {
|
|
57
|
+
Arc::new(Self {
|
|
58
|
+
limit,
|
|
59
|
+
used: AtomicUsize::new(0),
|
|
60
|
+
parent,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[allow(deprecated)] // Keep the vendored crate's Rust 1.88 compatibility.
|
|
65
|
+
fn reserve(&self, bytes: usize) -> Result<()> {
|
|
66
|
+
self.used
|
|
67
|
+
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |used| {
|
|
68
|
+
used.checked_add(bytes).filter(|&next| next <= self.limit)
|
|
69
|
+
})
|
|
70
|
+
.map_err(|_| Error::StreamMemoryLimit)?;
|
|
71
|
+
if let Some(parent) = &self.parent {
|
|
72
|
+
if let Err(e) = parent.reserve(bytes) {
|
|
73
|
+
self.used.fetch_sub(bytes, Ordering::Relaxed);
|
|
74
|
+
return Err(e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
Ok(())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fn release(&self, bytes: usize) {
|
|
81
|
+
self.used.fetch_sub(bytes, Ordering::Relaxed);
|
|
82
|
+
if let Some(parent) = &self.parent {
|
|
83
|
+
parent.release(bytes);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
44
88
|
/// Receive-side stream buffer.
|
|
45
89
|
///
|
|
46
90
|
/// Stream data received by the peer is buffered in a list of data chunks
|
|
@@ -52,6 +96,9 @@ pub struct RecvBuf {
|
|
|
52
96
|
/// the application, ordered by offset.
|
|
53
97
|
data: BTreeMap<u64, RangeBuf>,
|
|
54
98
|
|
|
99
|
+
memory: Option<Arc<ReceiveMemory>>,
|
|
100
|
+
reserved: usize,
|
|
101
|
+
|
|
55
102
|
/// The lowest data offset that has yet to be read by the application.
|
|
56
103
|
off: u64,
|
|
57
104
|
|
|
@@ -66,22 +113,62 @@ pub struct RecvBuf {
|
|
|
66
113
|
|
|
67
114
|
/// The error code received via RESET_STREAM.
|
|
68
115
|
error: Option<u64>,
|
|
116
|
+
/// After a reset, the receiver still owes the application this prefix.
|
|
117
|
+
reliable_size: u64,
|
|
118
|
+
reset_pending: bool,
|
|
69
119
|
|
|
70
120
|
/// Whether incoming data is validated but not buffered.
|
|
71
121
|
drain: bool,
|
|
72
122
|
}
|
|
73
123
|
|
|
124
|
+
impl Drop for RecvBuf {
|
|
125
|
+
fn drop(&mut self) {
|
|
126
|
+
self.clear();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
74
130
|
impl RecvBuf {
|
|
75
131
|
/// Creates a new receive buffer.
|
|
76
132
|
pub fn new(max_data: u64, initial_window: u64, max_window: u64) -> RecvBuf {
|
|
77
|
-
RecvBuf
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
133
|
+
let mut recv = RecvBuf::default();
|
|
134
|
+
recv.flow_control = flowcontrol::FlowControl::new(max_data, initial_window, max_window);
|
|
135
|
+
recv
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
pub(crate) fn set_memory_budget(&mut self, budget: Option<Arc<ReceiveMemory>>) {
|
|
139
|
+
if self.memory.is_none() {
|
|
140
|
+
self.memory = budget;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
fn allocation_cost(buf: &RangeBuf) -> usize {
|
|
145
|
+
// Charge the backing allocation even when the retained slice is small.
|
|
146
|
+
// Include space for the range, tree entry and allocation bookkeeping.
|
|
147
|
+
buf.data.as_ref().len() + 192
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
fn insert(&mut self, buf: RangeBuf) -> Result<()> {
|
|
151
|
+
if let Some(memory) = &self.memory {
|
|
152
|
+
let cost = Self::allocation_cost(&buf);
|
|
153
|
+
memory.reserve(cost)?;
|
|
154
|
+
self.reserved += cost;
|
|
155
|
+
}
|
|
156
|
+
if let Some(previous) = self.data.insert(buf.max_off(), buf) {
|
|
157
|
+
self.release(Self::allocation_cost(&previous));
|
|
84
158
|
}
|
|
159
|
+
Ok(())
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fn release(&mut self, bytes: usize) {
|
|
163
|
+
if let Some(memory) = &self.memory {
|
|
164
|
+
self.reserved -= bytes;
|
|
165
|
+
memory.release(bytes);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fn clear(&mut self) {
|
|
170
|
+
self.data.clear();
|
|
171
|
+
self.release(self.reserved);
|
|
85
172
|
}
|
|
86
173
|
|
|
87
174
|
/// Inserts the given chunk of data in the buffer.
|
|
@@ -89,7 +176,7 @@ impl RecvBuf {
|
|
|
89
176
|
/// This also takes care of enforcing stream flow control limits, as well
|
|
90
177
|
/// as handling incoming data that overlaps data that is already in the
|
|
91
178
|
/// buffer.
|
|
92
|
-
pub fn write(&mut self, buf: RangeBuf) -> Result<()> {
|
|
179
|
+
pub fn write(&mut self, mut buf: RangeBuf) -> Result<()> {
|
|
93
180
|
if buf.max_off() > self.max_data() {
|
|
94
181
|
return Err(Error::FlowControl);
|
|
95
182
|
}
|
|
@@ -111,32 +198,51 @@ impl RecvBuf {
|
|
|
111
198
|
return Err(Error::FinalSize);
|
|
112
199
|
}
|
|
113
200
|
|
|
201
|
+
if self.error.is_some() {
|
|
202
|
+
if self.drain || buf.off() >= self.reliable_size {
|
|
203
|
+
return Ok(());
|
|
204
|
+
}
|
|
205
|
+
if buf.max_off() > self.reliable_size {
|
|
206
|
+
let _ = buf.split_off((self.reliable_size - buf.off()) as usize);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
114
210
|
// We already saved the final offset, so there's nothing else we
|
|
115
211
|
// need to keep from the RangeBuf if it's empty.
|
|
116
212
|
if self.fin_off.is_some() && buf.is_empty() {
|
|
117
213
|
return Ok(());
|
|
118
214
|
}
|
|
119
215
|
|
|
120
|
-
|
|
216
|
+
let new_fin = buf.fin() && self.fin_off.is_none();
|
|
217
|
+
|
|
218
|
+
if new_fin {
|
|
121
219
|
self.fin_off = Some(buf.max_off());
|
|
122
220
|
}
|
|
123
221
|
|
|
124
|
-
// No need to store empty buffer that doesn't carry the fin flag
|
|
222
|
+
// No need to store empty buffer that doesn't carry the fin flag, but
|
|
223
|
+
// its offset still advances the largest received offset used by flow
|
|
224
|
+
// control (RFC 9000 Section 19.8).
|
|
125
225
|
if !buf.fin() && buf.is_empty() {
|
|
226
|
+
self.len = cmp::max(self.len, buf.max_off());
|
|
227
|
+
|
|
228
|
+
if self.drain {
|
|
229
|
+
// we are not storing any data, off == len
|
|
230
|
+
self.off = self.len;
|
|
231
|
+
}
|
|
232
|
+
|
|
126
233
|
return Ok(());
|
|
127
234
|
}
|
|
128
235
|
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// By this point all spurious empty buffers should have already been
|
|
136
|
-
// discarded, so allowing empty buffers here should be safe.
|
|
137
|
-
if !buf.is_empty() {
|
|
236
|
+
// Discard consumed data unless it carries the first FIN. Such data is
|
|
237
|
+
// replaced with an empty buffer at the final size, so the application
|
|
238
|
+
// reads the FIN without receiving duplicate data and the queued buffer
|
|
239
|
+
// does not keep the duplicate payload alive.
|
|
240
|
+
if self.off >= buf.max_off() && !buf.is_empty() {
|
|
241
|
+
if !new_fin {
|
|
138
242
|
return Ok(());
|
|
139
243
|
}
|
|
244
|
+
|
|
245
|
+
buf = RangeBuf::from(b"", buf.max_off(), true);
|
|
140
246
|
}
|
|
141
247
|
|
|
142
248
|
let mut tmp_bufs = VecDeque::with_capacity(2);
|
|
@@ -179,8 +285,7 @@ impl RecvBuf {
|
|
|
179
285
|
|
|
180
286
|
// New buffer's end overlaps existing buffer.
|
|
181
287
|
if off < b.off() && buf.max_off() > b.off() {
|
|
182
|
-
tmp_bufs
|
|
183
|
-
.push_back(buf.split_off((b.off() - off) as usize));
|
|
288
|
+
tmp_bufs.push_back(buf.split_off((b.off() - off) as usize));
|
|
184
289
|
}
|
|
185
290
|
}
|
|
186
291
|
}
|
|
@@ -188,7 +293,7 @@ impl RecvBuf {
|
|
|
188
293
|
self.len = cmp::max(self.len, buf.max_off());
|
|
189
294
|
|
|
190
295
|
if !self.drain {
|
|
191
|
-
self.
|
|
296
|
+
self.insert(buf)?;
|
|
192
297
|
} else {
|
|
193
298
|
// we are not storing any data, off == len
|
|
194
299
|
self.off = self.len;
|
|
@@ -228,7 +333,8 @@ impl RecvBuf {
|
|
|
228
333
|
/// On success the amount of data read or discarded, and a flag indicating
|
|
229
334
|
/// if there is no more data in the buffer, are returned as a tuple.
|
|
230
335
|
pub fn emit_or_discard<B: bytes::BufMut>(
|
|
231
|
-
&mut self,
|
|
336
|
+
&mut self,
|
|
337
|
+
mut action: RecvAction<B>,
|
|
232
338
|
) -> Result<(usize, bool)> {
|
|
233
339
|
let mut len = 0;
|
|
234
340
|
let mut cap = match &action {
|
|
@@ -242,12 +348,16 @@ impl RecvBuf {
|
|
|
242
348
|
|
|
243
349
|
// The stream was reset, so clear its data and return the error code
|
|
244
350
|
// instead.
|
|
245
|
-
if let Some(e) = self.error {
|
|
246
|
-
self.
|
|
351
|
+
if let Some(e) = self.error.filter(|_| self.is_fin()) {
|
|
352
|
+
self.clear();
|
|
353
|
+
self.reset_pending = false;
|
|
247
354
|
return Err(Error::StreamReset(e));
|
|
248
355
|
}
|
|
356
|
+
if self.error.is_some() {
|
|
357
|
+
cap = cap.min((self.reliable_size - self.off) as usize);
|
|
358
|
+
}
|
|
249
359
|
|
|
250
|
-
while
|
|
360
|
+
while self.ready() && (self.error.is_none() || self.off < self.reliable_size) {
|
|
251
361
|
let mut entry = match self.data.first_entry() {
|
|
252
362
|
Some(entry) => entry,
|
|
253
363
|
None => break,
|
|
@@ -255,6 +365,10 @@ impl RecvBuf {
|
|
|
255
365
|
|
|
256
366
|
let buf = entry.get_mut();
|
|
257
367
|
|
|
368
|
+
if cap == 0 && !buf.is_empty() {
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
|
|
258
372
|
let buf_len = cmp::min(buf.len(), cap);
|
|
259
373
|
|
|
260
374
|
// Only copy data if we're emitting, not discarding.
|
|
@@ -263,10 +377,7 @@ impl RecvBuf {
|
|
|
263
377
|
// impls are allowed to grow the buffer, so we
|
|
264
378
|
// check here that we still have at least
|
|
265
379
|
// `cap` bytes, but we can't require equality
|
|
266
|
-
debug_assert!(
|
|
267
|
-
cap <= out.remaining_mut(),
|
|
268
|
-
"We updated `cap` incorrectly"
|
|
269
|
-
);
|
|
380
|
+
debug_assert!(cap <= out.remaining_mut(), "We updated `cap` incorrectly");
|
|
270
381
|
out.put_slice(&buf[..buf_len])
|
|
271
382
|
}
|
|
272
383
|
|
|
@@ -282,13 +393,19 @@ impl RecvBuf {
|
|
|
282
393
|
break;
|
|
283
394
|
}
|
|
284
395
|
|
|
285
|
-
entry.remove();
|
|
396
|
+
let removed = entry.remove();
|
|
397
|
+
self.release(Self::allocation_cost(&removed));
|
|
286
398
|
}
|
|
287
399
|
|
|
288
400
|
// Update consumed bytes for flow control.
|
|
289
401
|
self.flow_control.add_consumed(len as u64);
|
|
290
402
|
|
|
291
|
-
|
|
403
|
+
if self.error.is_some() && self.off == self.reliable_size {
|
|
404
|
+
self.off = self.len;
|
|
405
|
+
self.clear();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
Ok((len, self.is_fin() && self.error.is_none()))
|
|
292
409
|
}
|
|
293
410
|
|
|
294
411
|
/// The final size supplied by FIN or RESET_STREAM, if known.
|
|
@@ -297,9 +414,26 @@ impl RecvBuf {
|
|
|
297
414
|
}
|
|
298
415
|
|
|
299
416
|
/// Resets the stream at the given offset.
|
|
300
|
-
pub fn reset(
|
|
301
|
-
|
|
417
|
+
pub fn reset(&mut self, error_code: u64, final_size: u64) -> Result<RecvBufResetReturn> {
|
|
418
|
+
self.reset_at(error_code, final_size, 0)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
pub fn reset_error(&self) -> Option<u64> {
|
|
422
|
+
self.error
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/// Signal the reset after delivering the reliable prefix, releasing credit
|
|
426
|
+
/// for the tail immediately.
|
|
427
|
+
pub fn reset_at(
|
|
428
|
+
&mut self,
|
|
429
|
+
error_code: u64,
|
|
430
|
+
final_size: u64,
|
|
431
|
+
reliable_size: u64,
|
|
302
432
|
) -> Result<RecvBufResetReturn> {
|
|
433
|
+
if reliable_size > final_size {
|
|
434
|
+
return Err(Error::InvalidFrame);
|
|
435
|
+
}
|
|
436
|
+
|
|
303
437
|
// Stream's size is already known, forbid changing it.
|
|
304
438
|
if let Some(fin_off) = self.fin_off {
|
|
305
439
|
if fin_off != final_size {
|
|
@@ -312,29 +446,39 @@ impl RecvBuf {
|
|
|
312
446
|
return Err(Error::FinalSize);
|
|
313
447
|
}
|
|
314
448
|
|
|
315
|
-
if self.
|
|
316
|
-
|
|
449
|
+
if final_size > self.max_data() {
|
|
450
|
+
return Err(Error::FlowControl);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if self.error.is_some() && self.is_fin() {
|
|
317
454
|
return Ok(RecvBufResetReturn::zero());
|
|
318
455
|
}
|
|
319
456
|
|
|
320
|
-
|
|
321
|
-
|
|
457
|
+
let notify = !self.drain && (!self.is_fin() || self.ready());
|
|
458
|
+
let previous_limit = if self.error.is_some() {
|
|
459
|
+
self.reliable_size
|
|
460
|
+
} else {
|
|
461
|
+
final_size
|
|
462
|
+
};
|
|
463
|
+
let limit = if self.drain {
|
|
464
|
+
self.off
|
|
465
|
+
} else {
|
|
466
|
+
reliable_size.min(previous_limit).max(self.off)
|
|
467
|
+
};
|
|
322
468
|
let result = RecvBufResetReturn {
|
|
323
469
|
max_data_delta: final_size - self.len,
|
|
324
|
-
consumed_flowcontrol:
|
|
470
|
+
consumed_flowcontrol: previous_limit - limit,
|
|
325
471
|
};
|
|
326
472
|
|
|
327
473
|
self.error = Some(error_code);
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
self.
|
|
331
|
-
|
|
332
|
-
self.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
let buf = RangeBuf::from(b"", final_size, true);
|
|
337
|
-
self.write(buf)?;
|
|
474
|
+
self.fin_off = Some(final_size);
|
|
475
|
+
self.len = final_size;
|
|
476
|
+
self.reliable_size = limit;
|
|
477
|
+
self.reset_pending = notify;
|
|
478
|
+
if self.off == limit {
|
|
479
|
+
self.off = final_size;
|
|
480
|
+
self.clear();
|
|
481
|
+
}
|
|
338
482
|
|
|
339
483
|
Ok(result)
|
|
340
484
|
}
|
|
@@ -374,9 +518,14 @@ impl RecvBuf {
|
|
|
374
518
|
|
|
375
519
|
self.drain = true;
|
|
376
520
|
|
|
377
|
-
self.
|
|
521
|
+
self.clear();
|
|
378
522
|
|
|
379
|
-
let consumed = self.
|
|
523
|
+
let consumed = if self.error.is_some() {
|
|
524
|
+
self.reliable_size.saturating_sub(self.off)
|
|
525
|
+
} else {
|
|
526
|
+
self.max_off() - self.off
|
|
527
|
+
};
|
|
528
|
+
self.reset_pending = false;
|
|
380
529
|
self.off = self.max_off();
|
|
381
530
|
|
|
382
531
|
Ok(consumed)
|
|
@@ -416,6 +565,9 @@ impl RecvBuf {
|
|
|
416
565
|
|
|
417
566
|
/// Returns true if the stream has data to be read.
|
|
418
567
|
pub fn ready(&self) -> bool {
|
|
568
|
+
if self.error.is_some() && self.is_fin() {
|
|
569
|
+
return self.reset_pending;
|
|
570
|
+
}
|
|
419
571
|
let (_, buf) = match self.data.first_key_value() {
|
|
420
572
|
Some(v) => v,
|
|
421
573
|
None => return false,
|
|
@@ -424,6 +576,41 @@ impl RecvBuf {
|
|
|
424
576
|
buf.off() == self.off
|
|
425
577
|
}
|
|
426
578
|
|
|
579
|
+
/// Returns the number of bytes that can be read contiguously from the
|
|
580
|
+
/// current read offset, up to `max_len`.
|
|
581
|
+
///
|
|
582
|
+
/// Data buffered behind a gap (received out of order) is not counted, so
|
|
583
|
+
/// this never reports bytes that are not yet readable. The cost is
|
|
584
|
+
/// proportional to the number of contiguous buffered chunks at the front
|
|
585
|
+
/// of the buffer, up to `max_len`; no data is copied.
|
|
586
|
+
pub fn readable_len(&self, max_len: usize) -> usize {
|
|
587
|
+
let max_len = if self.error.is_some() {
|
|
588
|
+
max_len.min(self.reliable_size.saturating_sub(self.off) as usize)
|
|
589
|
+
} else {
|
|
590
|
+
max_len
|
|
591
|
+
};
|
|
592
|
+
let mut contiguous = 0usize;
|
|
593
|
+
let mut next_off = self.off;
|
|
594
|
+
|
|
595
|
+
// `data` is ordered by offset, so walk from the front and stop at the
|
|
596
|
+
// first gap (a chunk that does not start where the contiguous run so
|
|
597
|
+
// far leaves off).
|
|
598
|
+
for buf in self.data.values() {
|
|
599
|
+
if buf.off() != next_off {
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
contiguous = contiguous.saturating_add(buf.len()).min(max_len);
|
|
604
|
+
next_off = buf.max_off();
|
|
605
|
+
|
|
606
|
+
if contiguous == max_len {
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
contiguous
|
|
612
|
+
}
|
|
613
|
+
|
|
427
614
|
#[cfg(test)]
|
|
428
615
|
pub(crate) fn flow_control_for_tests(&self) -> &flowcontrol::FlowControl {
|
|
429
616
|
&self.flow_control
|
|
@@ -433,10 +620,67 @@ impl RecvBuf {
|
|
|
433
620
|
#[cfg(test)]
|
|
434
621
|
mod tests {
|
|
435
622
|
use super::*;
|
|
436
|
-
|
|
623
|
+
|
|
624
|
+
/// The default size of the receiver stream flow control window.
|
|
625
|
+
const DEFAULT_STREAM_WINDOW: u64 = 32 * 1024;
|
|
437
626
|
use bytes::BufMut as _;
|
|
438
627
|
use rstest::rstest;
|
|
439
628
|
|
|
629
|
+
#[test]
|
|
630
|
+
fn reliable_reset_delivers_prefix_before_error() {
|
|
631
|
+
let mut recv = RecvBuf::new(32, 32, 32);
|
|
632
|
+
let reset = recv.reset_at(42, 10, 3).unwrap();
|
|
633
|
+
assert_eq!(reset.max_data_delta, 10);
|
|
634
|
+
assert_eq!(reset.consumed_flowcontrol, 7);
|
|
635
|
+
assert!(!recv.ready());
|
|
636
|
+
assert_eq!(recv.reset_at(42, 10, 5), Ok(RecvBufResetReturn::zero()));
|
|
637
|
+
recv.write(RangeBuf::from(b"abcde", 0, false)).unwrap();
|
|
638
|
+
assert_eq!(recv.readable_len(10), 3);
|
|
639
|
+
let mut data = [0; 10];
|
|
640
|
+
assert_eq!(recv.emit(&mut data), Ok((3, false)));
|
|
641
|
+
assert_eq!(&data[..3], b"abc");
|
|
642
|
+
assert_eq!(recv.emit(&mut data), Err(Error::StreamReset(42)));
|
|
643
|
+
assert_eq!(recv.emit(&mut data), Err(Error::Done));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
#[test]
|
|
647
|
+
fn reducing_reliable_size_returns_tail_credit_once() {
|
|
648
|
+
let mut recv = RecvBuf::new(32, 32, 32);
|
|
649
|
+
recv.write(RangeBuf::from(b"abcdef", 0, false)).unwrap();
|
|
650
|
+
assert_eq!(recv.reset_at(1, 10, 6).unwrap().consumed_flowcontrol, 4);
|
|
651
|
+
assert_eq!(recv.emit(&mut [0; 2]), Ok((2, false)));
|
|
652
|
+
assert_eq!(recv.reset_at(1, 10, 3).unwrap().consumed_flowcontrol, 3);
|
|
653
|
+
assert_eq!(recv.shutdown(), Ok(1));
|
|
654
|
+
assert_eq!(recv.reset(1, 10), Ok(RecvBufResetReturn::zero()));
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
#[test]
|
|
658
|
+
fn receive_memory_releases_on_read_shutdown_and_drop() {
|
|
659
|
+
let shared = ReceiveMemory::new(450, None);
|
|
660
|
+
let budget = ReceiveMemory::new(350, Some(shared.clone()));
|
|
661
|
+
let mut first = RecvBuf::new(512, 512, 512);
|
|
662
|
+
let mut second = RecvBuf::new(512, 512, 512);
|
|
663
|
+
first.set_memory_budget(Some(budget.clone()));
|
|
664
|
+
second.set_memory_budget(Some(ReceiveMemory::new(350, Some(shared.clone()))));
|
|
665
|
+
|
|
666
|
+
assert_eq!(first.write(RangeBuf::from(&[0; 64], 0, false)), Ok(()));
|
|
667
|
+
assert_eq!(
|
|
668
|
+
second.write(RangeBuf::from(&[0; 64], 0, false)),
|
|
669
|
+
Err(Error::StreamMemoryLimit)
|
|
670
|
+
);
|
|
671
|
+
assert_eq!(first.emit(&mut [0; 32]), Ok((32, false)));
|
|
672
|
+
assert_eq!(shared.used.load(Ordering::Relaxed), 256);
|
|
673
|
+
assert_eq!(first.emit(&mut [0; 32]), Ok((32, false)));
|
|
674
|
+
assert_eq!(shared.used.load(Ordering::Relaxed), 0);
|
|
675
|
+
assert_eq!(second.write(RangeBuf::from(&[0; 64], 0, false)), Ok(()));
|
|
676
|
+
assert_eq!(second.shutdown(), Ok(64));
|
|
677
|
+
assert_eq!(shared.used.load(Ordering::Relaxed), 0);
|
|
678
|
+
assert_eq!(first.write(RangeBuf::from(&[0; 64], 64, false)), Ok(()));
|
|
679
|
+
drop(first);
|
|
680
|
+
assert_eq!(budget.used.load(Ordering::Relaxed), 0);
|
|
681
|
+
assert_eq!(shared.used.load(Ordering::Relaxed), 0);
|
|
682
|
+
}
|
|
683
|
+
|
|
440
684
|
// Helper function for testing either buffer emit or discard.
|
|
441
685
|
//
|
|
442
686
|
// The `emit` parameter controls whether data is emitted or discarded from
|
|
@@ -455,8 +699,12 @@ mod tests {
|
|
|
455
699
|
// assert is performed against the bytes that were read out of the buffer,
|
|
456
700
|
// to ensure caller expectations are met.
|
|
457
701
|
fn assert_emit_discard(
|
|
458
|
-
recv: &mut RecvBuf,
|
|
459
|
-
|
|
702
|
+
recv: &mut RecvBuf,
|
|
703
|
+
emit: bool,
|
|
704
|
+
target_len: usize,
|
|
705
|
+
result_len: usize,
|
|
706
|
+
is_fin: bool,
|
|
707
|
+
test_bytes: Option<&[u8]>,
|
|
460
708
|
) {
|
|
461
709
|
let mut buf = Vec::<u8>::with_capacity(512).limit(target_len);
|
|
462
710
|
let action = if emit {
|
|
@@ -494,8 +742,7 @@ mod tests {
|
|
|
494
742
|
|
|
495
743
|
#[rstest]
|
|
496
744
|
fn empty_read(#[values(true, false)] emit: bool) {
|
|
497
|
-
let mut recv =
|
|
498
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
745
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
499
746
|
assert_eq!(recv.len, 0);
|
|
500
747
|
|
|
501
748
|
assert_emit_discard_done(&mut recv, emit);
|
|
@@ -503,8 +750,7 @@ mod tests {
|
|
|
503
750
|
|
|
504
751
|
#[rstest]
|
|
505
752
|
fn empty_stream_frame(#[values(true, false)] emit: bool) {
|
|
506
|
-
let mut recv =
|
|
507
|
-
RecvBuf::new(15, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
753
|
+
let mut recv = RecvBuf::new(15, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
508
754
|
assert_eq!(recv.len, 0);
|
|
509
755
|
|
|
510
756
|
let buf = RangeBuf::from(b"hello", 0, false);
|
|
@@ -515,10 +761,10 @@ mod tests {
|
|
|
515
761
|
|
|
516
762
|
assert_emit_discard(&mut recv, emit, 32, 5, false, None);
|
|
517
763
|
|
|
518
|
-
// Don't store non-fin empty buffer.
|
|
764
|
+
// Don't store non-fin empty buffer, but track its offset.
|
|
519
765
|
let buf = RangeBuf::from(b"", 10, false);
|
|
520
766
|
assert!(recv.write(buf).is_ok());
|
|
521
|
-
assert_eq!(recv.len,
|
|
767
|
+
assert_eq!(recv.len, 10);
|
|
522
768
|
assert_eq!(recv.off, 5);
|
|
523
769
|
assert_eq!(recv.data.len(), 0);
|
|
524
770
|
|
|
@@ -526,40 +772,50 @@ mod tests {
|
|
|
526
772
|
let buf = RangeBuf::from(b"", 16, false);
|
|
527
773
|
assert_eq!(recv.write(buf), Err(Error::FlowControl));
|
|
528
774
|
|
|
529
|
-
//
|
|
775
|
+
// A final size below the advanced largest offset is an error
|
|
776
|
+
// (RFC 9000 Section 4.5).
|
|
530
777
|
let buf = RangeBuf::from(b"", 5, true);
|
|
778
|
+
assert_eq!(recv.write(buf), Err(Error::FinalSize));
|
|
779
|
+
|
|
780
|
+
// Store fin empty buffer at the largest received offset.
|
|
781
|
+
let buf = RangeBuf::from(b"", 10, true);
|
|
531
782
|
assert!(recv.write(buf).is_ok());
|
|
532
|
-
assert_eq!(recv.len,
|
|
783
|
+
assert_eq!(recv.len, 10);
|
|
533
784
|
assert_eq!(recv.off, 5);
|
|
534
785
|
assert_eq!(recv.data.len(), 1);
|
|
535
786
|
|
|
536
787
|
// Don't store additional fin empty buffers.
|
|
537
|
-
let buf = RangeBuf::from(b"",
|
|
788
|
+
let buf = RangeBuf::from(b"", 10, true);
|
|
538
789
|
assert!(recv.write(buf).is_ok());
|
|
539
|
-
assert_eq!(recv.len,
|
|
790
|
+
assert_eq!(recv.len, 10);
|
|
540
791
|
assert_eq!(recv.off, 5);
|
|
541
792
|
assert_eq!(recv.data.len(), 1);
|
|
542
793
|
|
|
543
|
-
//
|
|
544
|
-
let buf = RangeBuf::from(b"aa",
|
|
794
|
+
// Accept another fin buffer with the same final size.
|
|
795
|
+
let buf = RangeBuf::from(b"aa", 8, true);
|
|
545
796
|
assert!(recv.write(buf).is_ok());
|
|
546
|
-
assert_eq!(recv.len,
|
|
797
|
+
assert_eq!(recv.len, 10);
|
|
547
798
|
assert_eq!(recv.off, 5);
|
|
548
799
|
assert_eq!(recv.data.len(), 1);
|
|
549
800
|
|
|
801
|
+
// A fin buffer whose end disagrees with the known final size errors.
|
|
802
|
+
let buf = RangeBuf::from(b"aa", 3, true);
|
|
803
|
+
assert_eq!(recv.write(buf), Err(Error::FinalSize));
|
|
804
|
+
|
|
550
805
|
// Validate final size with fin empty buffers.
|
|
551
|
-
let buf = RangeBuf::from(b"",
|
|
806
|
+
let buf = RangeBuf::from(b"", 11, true);
|
|
552
807
|
assert_eq!(recv.write(buf), Err(Error::FinalSize));
|
|
553
|
-
let buf = RangeBuf::from(b"",
|
|
808
|
+
let buf = RangeBuf::from(b"", 9, true);
|
|
554
809
|
assert_eq!(recv.write(buf), Err(Error::FinalSize));
|
|
555
810
|
|
|
556
|
-
|
|
811
|
+
// The range (5..10) was never received, so the stream cannot reach
|
|
812
|
+
// its fin and nothing further is readable.
|
|
813
|
+
assert_emit_discard_done(&mut recv, emit);
|
|
557
814
|
}
|
|
558
815
|
|
|
559
816
|
#[rstest]
|
|
560
817
|
fn ordered_read(#[values(true, false)] emit: bool) {
|
|
561
|
-
let mut recv =
|
|
562
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
818
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
563
819
|
assert_eq!(recv.len, 0);
|
|
564
820
|
|
|
565
821
|
let first = RangeBuf::from(b"hello", 0, false);
|
|
@@ -582,25 +838,36 @@ mod tests {
|
|
|
582
838
|
assert_eq!(recv.len, 19);
|
|
583
839
|
assert_eq!(recv.off, 0);
|
|
584
840
|
|
|
585
|
-
assert_emit_discard(
|
|
586
|
-
&mut recv,
|
|
587
|
-
emit,
|
|
588
|
-
32,
|
|
589
|
-
19,
|
|
590
|
-
true,
|
|
591
|
-
Some(b"helloworldsomething"),
|
|
592
|
-
);
|
|
841
|
+
assert_emit_discard(&mut recv, emit, 32, 19, true, Some(b"helloworldsomething"));
|
|
593
842
|
assert_eq!(recv.len, 19);
|
|
594
843
|
assert_eq!(recv.off, 19);
|
|
595
844
|
|
|
596
845
|
assert_emit_discard_done(&mut recv, emit);
|
|
597
846
|
}
|
|
598
847
|
|
|
848
|
+
#[test]
|
|
849
|
+
/// `readable_len` counts only contiguous in-order data, up to its limit.
|
|
850
|
+
fn readable_len() {
|
|
851
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
852
|
+
|
|
853
|
+
// Empty buffer: nothing readable.
|
|
854
|
+
assert_eq!(recv.readable_len(64 * 1024), 0);
|
|
855
|
+
|
|
856
|
+
// Data buffered behind a gap is not readable.
|
|
857
|
+
assert!(recv.write(RangeBuf::from(b"hello", 0, false)).is_ok());
|
|
858
|
+
assert!(recv.write(RangeBuf::from(b"something", 10, false)).is_ok());
|
|
859
|
+
assert_eq!(recv.readable_len(64 * 1024), 5);
|
|
860
|
+
|
|
861
|
+
// Filling the gap makes the full range readable, bounded by the limit.
|
|
862
|
+
assert!(recv.write(RangeBuf::from(b"world", 5, false)).is_ok());
|
|
863
|
+
assert_eq!(recv.readable_len(64 * 1024), 19);
|
|
864
|
+
assert_eq!(recv.readable_len(10), 10);
|
|
865
|
+
}
|
|
866
|
+
|
|
599
867
|
/// Test shutdown behavior
|
|
600
868
|
#[rstest]
|
|
601
869
|
fn shutdown(#[values(true, false)] emit: bool) {
|
|
602
|
-
let mut recv =
|
|
603
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
870
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
604
871
|
assert_eq!(recv.len, 0);
|
|
605
872
|
|
|
606
873
|
let first = RangeBuf::from(b"hello", 0, false);
|
|
@@ -650,10 +917,104 @@ mod tests {
|
|
|
650
917
|
assert_emit_discard_done(&mut recv, emit);
|
|
651
918
|
}
|
|
652
919
|
|
|
920
|
+
/// An empty non-fin buffer advances the largest received offset, which the
|
|
921
|
+
/// connection charges to flow control on arrival, so a draining stream must
|
|
922
|
+
/// consume it too and a later reset must not credit it again.
|
|
923
|
+
#[test]
|
|
924
|
+
fn shutdown_empty_stream_frame() {
|
|
925
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
926
|
+
|
|
927
|
+
assert!(recv.write(RangeBuf::from(b"hello", 0, false)).is_ok());
|
|
928
|
+
assert_eq!(recv.shutdown(), Ok(5));
|
|
929
|
+
|
|
930
|
+
assert!(recv.write(RangeBuf::from(b"", 10, false)).is_ok());
|
|
931
|
+
assert_eq!(recv.len, 10);
|
|
932
|
+
assert_eq!(recv.off, 10);
|
|
933
|
+
assert_eq!(recv.data.len(), 0);
|
|
934
|
+
|
|
935
|
+
assert_eq!(
|
|
936
|
+
recv.reset(42, 10),
|
|
937
|
+
Ok(RecvBufResetReturn {
|
|
938
|
+
max_data_delta: 0,
|
|
939
|
+
consumed_flowcontrol: 0,
|
|
940
|
+
})
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
#[rstest]
|
|
945
|
+
fn reset_after_fin(
|
|
946
|
+
#[values("unread", "partial", "gap", "empty", "consumed", "draining")] state: &str,
|
|
947
|
+
) {
|
|
948
|
+
let mut recv = RecvBuf::new(15, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
949
|
+
let mut out = [0; 5];
|
|
950
|
+
let (data, offset) = if state == "gap" {
|
|
951
|
+
(b"llo".as_slice(), 2)
|
|
952
|
+
} else {
|
|
953
|
+
(b"hello".as_slice(), 0)
|
|
954
|
+
};
|
|
955
|
+
recv.write(RangeBuf::from(data, offset, state != "empty"))
|
|
956
|
+
.unwrap();
|
|
957
|
+
|
|
958
|
+
match state {
|
|
959
|
+
"partial" => assert_eq!(recv.emit(&mut out[..2]), Ok((2, false))),
|
|
960
|
+
"consumed" => assert_eq!(recv.emit(&mut out), Ok((5, true))),
|
|
961
|
+
"empty" => {
|
|
962
|
+
assert_eq!(recv.emit(&mut out), Ok((5, false)));
|
|
963
|
+
recv.write(RangeBuf::from(b"", 5, true)).unwrap();
|
|
964
|
+
}
|
|
965
|
+
"draining" => assert_eq!(recv.shutdown(), Ok(5)),
|
|
966
|
+
_ => (),
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
let consumed = 5 - recv.off_front();
|
|
970
|
+
assert_eq!(
|
|
971
|
+
recv.reset(42, 5),
|
|
972
|
+
Ok(RecvBufResetReturn {
|
|
973
|
+
max_data_delta: 0,
|
|
974
|
+
consumed_flowcontrol: consumed,
|
|
975
|
+
})
|
|
976
|
+
);
|
|
977
|
+
assert!(recv.is_fin());
|
|
978
|
+
assert_eq!(recv.max_off(), 5);
|
|
979
|
+
assert_eq!(recv.ready(), state != "consumed" && state != "draining");
|
|
980
|
+
if recv.ready() {
|
|
981
|
+
assert_eq!(recv.emit(&mut out), Err(Error::StreamReset(42)));
|
|
982
|
+
}
|
|
983
|
+
assert_eq!(recv.emit(&mut out), Err(Error::Done));
|
|
984
|
+
assert_eq!(recv.reset(42, 5), Ok(RecvBufResetReturn::zero()));
|
|
985
|
+
recv.write(RangeBuf::from(b"hello", 0, true)).unwrap();
|
|
986
|
+
assert!(!recv.ready());
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
#[rstest]
|
|
990
|
+
fn duplicate_data_first_fin(#[values(true, false)] drain: bool) {
|
|
991
|
+
let mut recv = RecvBuf::new(15, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
992
|
+
let mut out = [0; 5];
|
|
993
|
+
recv.write(RangeBuf::from(b"hello", 0, false)).unwrap();
|
|
994
|
+
assert_eq!(recv.emit(&mut out), Ok((5, false)));
|
|
995
|
+
if drain {
|
|
996
|
+
assert_eq!(recv.shutdown(), Ok(0));
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
recv.write(RangeBuf::from(b"hello", 0, false)).unwrap();
|
|
1000
|
+
assert!(!recv.ready());
|
|
1001
|
+
recv.write(RangeBuf::from(b"hello", 0, true)).unwrap();
|
|
1002
|
+
assert!(recv.is_fin());
|
|
1003
|
+
assert_eq!(recv.ready(), !drain);
|
|
1004
|
+
assert!(recv.data.values().all(|buf| buf.data.as_ref().is_empty()));
|
|
1005
|
+
if !drain {
|
|
1006
|
+
assert_eq!(recv.emit(&mut out), Ok((0, true)));
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
recv.write(RangeBuf::from(b"hello", 0, true)).unwrap();
|
|
1010
|
+
recv.write(RangeBuf::from(b"", 5, true)).unwrap();
|
|
1011
|
+
assert!(!recv.ready());
|
|
1012
|
+
assert_eq!(recv.emit(&mut out), Err(Error::Done));
|
|
1013
|
+
}
|
|
1014
|
+
|
|
653
1015
|
#[rstest]
|
|
654
1016
|
fn split_read(#[values(true, false)] emit: bool) {
|
|
655
|
-
let mut recv =
|
|
656
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1017
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
657
1018
|
assert_eq!(recv.len, 0);
|
|
658
1019
|
|
|
659
1020
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -682,8 +1043,7 @@ mod tests {
|
|
|
682
1043
|
|
|
683
1044
|
#[test]
|
|
684
1045
|
fn split_read_incremental_buf() {
|
|
685
|
-
let mut recv =
|
|
686
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1046
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
687
1047
|
assert_eq!(recv.len, 0);
|
|
688
1048
|
|
|
689
1049
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -730,8 +1090,7 @@ mod tests {
|
|
|
730
1090
|
|
|
731
1091
|
#[rstest]
|
|
732
1092
|
fn incomplete_read(#[values(true, false)] emit: bool) {
|
|
733
|
-
let mut recv =
|
|
734
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1093
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
735
1094
|
assert_eq!(recv.len, 0);
|
|
736
1095
|
|
|
737
1096
|
let mut buf = [0u8; 32];
|
|
@@ -756,22 +1115,14 @@ mod tests {
|
|
|
756
1115
|
assert_eq!(recv.len, 19);
|
|
757
1116
|
assert_eq!(recv.off, 0);
|
|
758
1117
|
|
|
759
|
-
assert_emit_discard(
|
|
760
|
-
&mut recv,
|
|
761
|
-
emit,
|
|
762
|
-
32,
|
|
763
|
-
19,
|
|
764
|
-
true,
|
|
765
|
-
Some(b"somethinghelloworld"),
|
|
766
|
-
);
|
|
1118
|
+
assert_emit_discard(&mut recv, emit, 32, 19, true, Some(b"somethinghelloworld"));
|
|
767
1119
|
assert_eq!(recv.len, 19);
|
|
768
1120
|
assert_eq!(recv.off, 19);
|
|
769
1121
|
}
|
|
770
1122
|
|
|
771
1123
|
#[rstest]
|
|
772
1124
|
fn zero_len_read(#[values(true, false)] emit: bool) {
|
|
773
|
-
let mut recv =
|
|
774
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1125
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
775
1126
|
assert_eq!(recv.len, 0);
|
|
776
1127
|
|
|
777
1128
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -794,8 +1145,7 @@ mod tests {
|
|
|
794
1145
|
|
|
795
1146
|
#[rstest]
|
|
796
1147
|
fn past_read(#[values(true, false)] emit: bool) {
|
|
797
|
-
let mut recv =
|
|
798
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1148
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
799
1149
|
assert_eq!(recv.len, 0);
|
|
800
1150
|
|
|
801
1151
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -822,15 +1172,15 @@ mod tests {
|
|
|
822
1172
|
assert!(recv.write(fourth).is_ok());
|
|
823
1173
|
assert_eq!(recv.len, 9);
|
|
824
1174
|
assert_eq!(recv.off, 9);
|
|
825
|
-
assert_eq!(recv.data.len(),
|
|
1175
|
+
assert_eq!(recv.data.len(), 1);
|
|
826
1176
|
|
|
1177
|
+
assert_emit_discard(&mut recv, emit, 32, 0, true, Some(b""));
|
|
827
1178
|
assert_emit_discard_done(&mut recv, emit);
|
|
828
1179
|
}
|
|
829
1180
|
|
|
830
1181
|
#[rstest]
|
|
831
1182
|
fn fully_overlapping_read(#[values(true, false)] emit: bool) {
|
|
832
|
-
let mut recv =
|
|
833
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1183
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
834
1184
|
assert_eq!(recv.len, 0);
|
|
835
1185
|
|
|
836
1186
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -856,8 +1206,7 @@ mod tests {
|
|
|
856
1206
|
|
|
857
1207
|
#[rstest]
|
|
858
1208
|
fn fully_overlapping_read2(#[values(true, false)] emit: bool) {
|
|
859
|
-
let mut recv =
|
|
860
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1209
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
861
1210
|
assert_eq!(recv.len, 0);
|
|
862
1211
|
|
|
863
1212
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -883,8 +1232,7 @@ mod tests {
|
|
|
883
1232
|
|
|
884
1233
|
#[rstest]
|
|
885
1234
|
fn fully_overlapping_read3(#[values(true, false)] emit: bool) {
|
|
886
|
-
let mut recv =
|
|
887
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1235
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
888
1236
|
assert_eq!(recv.len, 0);
|
|
889
1237
|
|
|
890
1238
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -910,8 +1258,7 @@ mod tests {
|
|
|
910
1258
|
|
|
911
1259
|
#[rstest]
|
|
912
1260
|
fn fully_overlapping_read_multi(#[values(true, false)] emit: bool) {
|
|
913
|
-
let mut recv =
|
|
914
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1261
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
915
1262
|
assert_eq!(recv.len, 0);
|
|
916
1263
|
|
|
917
1264
|
let first = RangeBuf::from(b"somethingsomething", 0, false);
|
|
@@ -933,14 +1280,7 @@ mod tests {
|
|
|
933
1280
|
assert_eq!(recv.off, 0);
|
|
934
1281
|
assert_eq!(recv.data.len(), 5);
|
|
935
1282
|
|
|
936
|
-
assert_emit_discard(
|
|
937
|
-
&mut recv,
|
|
938
|
-
emit,
|
|
939
|
-
32,
|
|
940
|
-
18,
|
|
941
|
-
false,
|
|
942
|
-
Some(b"somhellogsomhellog"),
|
|
943
|
-
);
|
|
1283
|
+
assert_emit_discard(&mut recv, emit, 32, 18, false, Some(b"somhellogsomhellog"));
|
|
944
1284
|
assert_eq!(recv.len, 18);
|
|
945
1285
|
assert_eq!(recv.off, 18);
|
|
946
1286
|
assert_eq!(recv.data.len(), 0);
|
|
@@ -950,8 +1290,7 @@ mod tests {
|
|
|
950
1290
|
|
|
951
1291
|
#[rstest]
|
|
952
1292
|
fn overlapping_start_read(#[values(true, false)] emit: bool) {
|
|
953
|
-
let mut recv =
|
|
954
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1293
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
955
1294
|
assert_eq!(recv.len, 0);
|
|
956
1295
|
|
|
957
1296
|
let first = RangeBuf::from(b"something", 0, false);
|
|
@@ -967,14 +1306,7 @@ mod tests {
|
|
|
967
1306
|
assert_eq!(recv.off, 0);
|
|
968
1307
|
assert_eq!(recv.data.len(), 2);
|
|
969
1308
|
|
|
970
|
-
assert_emit_discard(
|
|
971
|
-
&mut recv,
|
|
972
|
-
emit,
|
|
973
|
-
32,
|
|
974
|
-
13,
|
|
975
|
-
true,
|
|
976
|
-
Some(b"somethingello"),
|
|
977
|
-
);
|
|
1309
|
+
assert_emit_discard(&mut recv, emit, 32, 13, true, Some(b"somethingello"));
|
|
978
1310
|
|
|
979
1311
|
assert_eq!(recv.len, 13);
|
|
980
1312
|
assert_eq!(recv.off, 13);
|
|
@@ -984,8 +1316,7 @@ mod tests {
|
|
|
984
1316
|
|
|
985
1317
|
#[rstest]
|
|
986
1318
|
fn overlapping_end_read(#[values(true, false)] emit: bool) {
|
|
987
|
-
let mut recv =
|
|
988
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1319
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
989
1320
|
assert_eq!(recv.len, 0);
|
|
990
1321
|
|
|
991
1322
|
let first = RangeBuf::from(b"hello", 0, false);
|
|
@@ -1010,8 +1341,7 @@ mod tests {
|
|
|
1010
1341
|
|
|
1011
1342
|
#[rstest]
|
|
1012
1343
|
fn overlapping_end_twice_read(#[values(true, false)] emit: bool) {
|
|
1013
|
-
let mut recv =
|
|
1014
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1344
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1015
1345
|
assert_eq!(recv.len, 0);
|
|
1016
1346
|
|
|
1017
1347
|
let first = RangeBuf::from(b"he", 0, false);
|
|
@@ -1047,11 +1377,8 @@ mod tests {
|
|
|
1047
1377
|
}
|
|
1048
1378
|
|
|
1049
1379
|
#[rstest]
|
|
1050
|
-
fn overlapping_end_twice_and_contained_read(
|
|
1051
|
-
|
|
1052
|
-
) {
|
|
1053
|
-
let mut recv =
|
|
1054
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1380
|
+
fn overlapping_end_twice_and_contained_read(#[values(true, false)] emit: bool) {
|
|
1381
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1055
1382
|
assert_eq!(recv.len, 0);
|
|
1056
1383
|
|
|
1057
1384
|
let first = RangeBuf::from(b"hellow", 0, false);
|
|
@@ -1079,14 +1406,7 @@ mod tests {
|
|
|
1079
1406
|
assert_eq!(recv.off, 0);
|
|
1080
1407
|
assert_eq!(recv.data.len(), 5);
|
|
1081
1408
|
|
|
1082
|
-
assert_emit_discard(
|
|
1083
|
-
&mut recv,
|
|
1084
|
-
emit,
|
|
1085
|
-
32,
|
|
1086
|
-
16,
|
|
1087
|
-
true,
|
|
1088
|
-
Some(b"helloworldbarfoo"),
|
|
1089
|
-
);
|
|
1409
|
+
assert_emit_discard(&mut recv, emit, 32, 16, true, Some(b"helloworldbarfoo"));
|
|
1090
1410
|
assert_eq!(recv.len, 16);
|
|
1091
1411
|
assert_eq!(recv.off, 16);
|
|
1092
1412
|
|
|
@@ -1094,11 +1414,8 @@ mod tests {
|
|
|
1094
1414
|
}
|
|
1095
1415
|
|
|
1096
1416
|
#[rstest]
|
|
1097
|
-
fn partially_multi_overlapping_reordered_read(
|
|
1098
|
-
|
|
1099
|
-
) {
|
|
1100
|
-
let mut recv =
|
|
1101
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1417
|
+
fn partially_multi_overlapping_reordered_read(#[values(true, false)] emit: bool) {
|
|
1418
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1102
1419
|
assert_eq!(recv.len, 0);
|
|
1103
1420
|
|
|
1104
1421
|
let first = RangeBuf::from(b"hello", 8, false);
|
|
@@ -1120,14 +1437,7 @@ mod tests {
|
|
|
1120
1437
|
assert_eq!(recv.off, 0);
|
|
1121
1438
|
assert_eq!(recv.data.len(), 3);
|
|
1122
1439
|
|
|
1123
|
-
assert_emit_discard(
|
|
1124
|
-
&mut recv,
|
|
1125
|
-
emit,
|
|
1126
|
-
32,
|
|
1127
|
-
15,
|
|
1128
|
-
true,
|
|
1129
|
-
Some(b"somethinhelloar"),
|
|
1130
|
-
);
|
|
1440
|
+
assert_emit_discard(&mut recv, emit, 32, 15, true, Some(b"somethinhelloar"));
|
|
1131
1441
|
assert_eq!(recv.len, 15);
|
|
1132
1442
|
assert_eq!(recv.off, 15);
|
|
1133
1443
|
assert_eq!(recv.data.len(), 0);
|
|
@@ -1136,11 +1446,8 @@ mod tests {
|
|
|
1136
1446
|
}
|
|
1137
1447
|
|
|
1138
1448
|
#[rstest]
|
|
1139
|
-
fn partially_multi_overlapping_reordered_read2(
|
|
1140
|
-
|
|
1141
|
-
) {
|
|
1142
|
-
let mut recv =
|
|
1143
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1449
|
+
fn partially_multi_overlapping_reordered_read2(#[values(true, false)] emit: bool) {
|
|
1450
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1144
1451
|
assert_eq!(recv.len, 0);
|
|
1145
1452
|
|
|
1146
1453
|
let first = RangeBuf::from(b"aaa", 0, false);
|
|
@@ -1180,14 +1487,7 @@ mod tests {
|
|
|
1180
1487
|
assert_eq!(recv.off, 0);
|
|
1181
1488
|
assert_eq!(recv.data.len(), 6);
|
|
1182
1489
|
|
|
1183
|
-
assert_emit_discard(
|
|
1184
|
-
&mut recv,
|
|
1185
|
-
emit,
|
|
1186
|
-
32,
|
|
1187
|
-
14,
|
|
1188
|
-
false,
|
|
1189
|
-
Some(b"aabbbcdddeefff"),
|
|
1190
|
-
);
|
|
1490
|
+
assert_emit_discard(&mut recv, emit, 32, 14, false, Some(b"aabbbcdddeefff"));
|
|
1191
1491
|
assert_eq!(recv.len, 14);
|
|
1192
1492
|
assert_eq!(recv.off, 14);
|
|
1193
1493
|
assert_eq!(recv.data.len(), 0);
|
|
@@ -1197,8 +1497,7 @@ mod tests {
|
|
|
1197
1497
|
|
|
1198
1498
|
#[test]
|
|
1199
1499
|
fn mixed_read_actions() {
|
|
1200
|
-
let mut recv =
|
|
1201
|
-
RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1500
|
+
let mut recv = RecvBuf::new(u64::MAX, DEFAULT_STREAM_WINDOW, DEFAULT_STREAM_WINDOW);
|
|
1202
1501
|
assert_eq!(recv.len, 0);
|
|
1203
1502
|
|
|
1204
1503
|
let first = RangeBuf::from(b"hello", 0, false);
|