shadowsocks_service/net/
flow.rs1use std::sync::atomic::Ordering;
4
5#[cfg(target_has_atomic = "64")]
6type FlowCounter = std::sync::atomic::AtomicU64;
7#[cfg(not(target_has_atomic = "64"))]
8type FlowCounter = std::sync::atomic::AtomicU32;
9
10pub struct FlowStat {
12 tx: FlowCounter,
13 rx: FlowCounter,
14}
15
16impl Default for FlowStat {
17 fn default() -> Self {
18 Self {
19 tx: FlowCounter::new(0),
20 rx: FlowCounter::new(0),
21 }
22 }
23}
24
25impl FlowStat {
26 pub fn new() -> Self {
28 Self::default()
29 }
30
31 pub fn tx(&self) -> u64 {
33 self.tx.load(Ordering::Relaxed) as _
34 }
35
36 pub fn incr_tx(&self, n: u64) {
38 self.tx.fetch_add(n as _, Ordering::AcqRel);
39 }
40
41 pub fn rx(&self) -> u64 {
43 self.rx.load(Ordering::Relaxed) as _
44 }
45
46 pub fn incr_rx(&self, n: u64) {
48 self.rx.fetch_add(n as _, Ordering::AcqRel);
49 }
50}