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
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Serialize, Deserialize)]
pub enum ResourceLimit
{
Finite(u64),
Infinite,
}
impl ResourceLimit
{
const Infinity: rlim64_t = ::libc::RLIM_INFINITY as rlim64_t;
pub fn maximum_number_of_open_file_descriptors(proc_path: &ProcPath) -> Result<ResourceLimit, io::Error>
{
Ok(ResourceLimit::Finite(proc_path.maximum_number_of_open_file_descriptors()?))
}
#[inline(always)]
pub fn value(&self) -> u64
{
use self::ResourceLimit::*;
match *self
{
Finite(limit) => limit,
Infinite => ::std::u64::MAX,
}
}
#[inline(always)]
pub(crate) fn convert(value: rlim64_t) -> ResourceLimit
{
use self::ResourceLimit::*;
if value >= Self::Infinity
{
Infinite
}
else
{
Finite(value)
}
}
#[inline(always)]
pub(crate) fn unwrap(&self) -> rlim64_t
{
use self::ResourceLimit::*;
match *self
{
Finite(limit) =>
{
assert!(limit < Self::Infinity, "limit '{}' equals or exceeds Infinity '{}'", limit, Self::Infinity);
limit
},
Infinite => Self::Infinity
}
}
#[inline(always)]
pub(crate) fn is_finite(&self) -> bool
{
match *self
{
ResourceLimit::Finite(_) => true,
_ => false,
}
}
#[inline(always)]
pub(crate) fn is_infinite(&self) -> bool
{
match *self
{
ResourceLimit::Infinite => true,
_ => false,
}
}
}