mio/sys/unix/selector/
stateless_io_source.rs

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
//! Both `kqueue(2)` and `epoll(2)` don't need to hold any user space state.

use std::io;
use std::os::fd::RawFd;

use crate::{Interest, Registry, Token};

pub(crate) struct IoSourceState;

impl IoSourceState {
    pub(crate) fn new() -> IoSourceState {
        IoSourceState
    }

    pub(crate) fn do_io<T, F, R>(&self, f: F, io: &T) -> io::Result<R>
    where
        F: FnOnce(&T) -> io::Result<R>,
    {
        // We don't hold state, so we can just call the function and
        // return.
        f(io)
    }

    pub(crate) fn register(
        &mut self,
        registry: &Registry,
        token: Token,
        interests: Interest,
        fd: RawFd,
    ) -> io::Result<()> {
        // Pass through, we don't have any state.
        registry.selector().register(fd, token, interests)
    }

    pub(crate) fn reregister(
        &mut self,
        registry: &Registry,
        token: Token,
        interests: Interest,
        fd: RawFd,
    ) -> io::Result<()> {
        // Pass through, we don't have any state.
        registry.selector().reregister(fd, token, interests)
    }

    pub(crate) fn deregister(&mut self, registry: &Registry, fd: RawFd) -> io::Result<()> {
        // Pass through, we don't have any state.
        registry.selector().deregister(fd)
    }
}