1#[macro_export]
2macro_rules! base_pool_impl {
3 (
4 $state:ident
5 ) => {
6 fn set_max_conn(&self, mut max: Option<usize>) {
7 if let Some(0) = max {
8 max = None;
9 }
10 match max {
11 None => self
12 .$state
13 .max_conn
14 .store(usize::MAX, std::sync::atomic::Ordering::Relaxed),
15 Some(v) => self
16 .$state
17 .max_conn
18 .store(v, std::sync::atomic::Ordering::Relaxed),
19 }
20 }
21
22 fn get_max_conn(&self) -> Option<usize> {
23 match self
24 .$state
25 .max_conn
26 .load(std::sync::atomic::Ordering::Relaxed)
27 {
28 usize::MAX => None,
29 v => Some(v),
30 }
31 }
32
33 fn get_cur_conn(&self) -> usize {
34 self.$state
35 .cur_conn
36 .load(std::sync::atomic::Ordering::Relaxed)
37 }
38
39 fn set_keepalive(&self, mut duration: Option<std::time::Duration>) {
40 if let Some(d) = duration {
41 if d.is_zero() {
42 duration = None;
43 }
44 }
45
46 match duration {
47 None => self
48 .$state
49 .keepalive
50 .store(u64::MAX, std::sync::atomic::Ordering::Relaxed),
51 Some(v) => self
52 .$state
53 .keepalive
54 .store(v.as_secs(), std::sync::atomic::Ordering::Relaxed),
55 }
56 }
57
58 fn get_keepalive(&self) -> Option<std::time::Duration> {
59 match self
60 .$state
61 .keepalive
62 .load(std::sync::atomic::Ordering::Relaxed)
63 {
64 u64::MAX => None,
65 v => Some(std::time::Duration::from_secs(v)),
66 }
67 }
68
69 fn get_strategy(&self) -> Arc<dyn LbStrategy> {
70 self.$state.lb_strategy.clone()
71 }
72 };
73}
74
75#[allow(unused_imports)]
76pub use base_pool_impl;