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
use std::io;
use std::default::Default;
use mio::util::Slab;
use mio::{EventLoop, EventLoopConfig};
use handler::Handler;
use {Machine};
#[derive(Debug, Clone)]
pub struct Config {
mio: EventLoopConfig,
slab_capacity: usize,
}
impl Default for Config {
fn default() -> Config {
Config {
mio: Default::default(),
slab_capacity: 4096,
}
}
}
impl Config {
pub fn new() -> Config {
Config {
mio: EventLoopConfig::new(),
slab_capacity: 4096,
}
}
pub fn mio(&mut self) -> &mut EventLoopConfig {
&mut self.mio
}
pub fn slab_capacity(&mut self, capacity: usize) {
self.slab_capacity = capacity;
}
}
pub fn create_slab<M:Sized>(cfg: &Config) -> Slab<M> {
Slab::new(cfg.slab_capacity)
}
pub fn create_loop<M: Machine>(cfg: &Config)
-> Result<EventLoop<Handler<M>>, io::Error>
{
EventLoop::configured(cfg.mio.clone())
}