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
//! Requests whose stream the client could no longer receive.
//!
//! A module stream chunk larger than the client's egress budget ends the
//! client's view of that request with `frame_too_large`, but the module may
//! still be computing it. The request keeps its credit, so a Serial route admits
//! nothing new and a drain keeps waiting, until the module's own terminal frame
//! arrives; every frame of that correlation in between is dropped instead of
//! reaching a client that already saw the request end.
use std::sync::atomic::Ordering;
use super::ChannelFlow;
impl ChannelFlow {
/// Stop delivering `corr` to the client. Its credit stays held until the
/// module's terminal frame for it is passed to [`Self::drop_refused_frame`].
pub(crate) fn refuse_client_delivery(&self, corr: u64) {
let mut state = self
.state
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
if state.refused.insert(corr) {
self.refused_count.fetch_add(1, Ordering::Release);
}
}
/// Whether a module frame for `corr` must be dropped because the client's
/// delivery of that request already ended. A terminal frame also ends the
/// refusal and releases the request's credit. Routes with no refused
/// request pay one atomic load per frame and take no lock.
pub(crate) fn drop_refused_frame(&self, corr: u64, terminal: bool) -> bool {
if self.refused_count.load(Ordering::Acquire) == 0 {
return false;
}
let mut state = self
.state
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
if !state.refused.contains(&corr) {
return false;
}
if terminal {
state.refused.remove(&corr);
self.refused_count.fetch_sub(1, Ordering::Release);
drop(state);
self.release_corr(corr);
}
true
}
}