1//! Both `kqueue(2)` and `epoll(2)` don't need to hold any user space state.
2
3use std::io;
4use std::os::fd::RawFd;
5
6use crate::{Interest, Registry, Token};
7
8pub(crate) struct IoSourceState;
9
10impl IoSourceState {
11 pub(crate) fn new() -> IoSourceState {
12 IoSourceState
13 }
14
15 pub(crate) fn do_io<T, F, R>(&self, f: F, io: &T) -> io::Result<R>
16 where
17 F: FnOnce(&T) -> io::Result<R>,
18 {
19 // We don't hold state, so we can just call the function and
20 // return.
21 f(io)
22 }
23
24 pub(crate) fn register(
25 &mut self,
26 registry: &Registry,
27 token: Token,
28 interests: Interest,
29 fd: RawFd,
30 ) -> io::Result<()> {
31 // Pass through, we don't have any state.
32 registry.selector().register(fd, token, interests)
33 }
34
35 pub(crate) fn reregister(
36 &mut self,
37 registry: &Registry,
38 token: Token,
39 interests: Interest,
40 fd: RawFd,
41 ) -> io::Result<()> {
42 // Pass through, we don't have any state.
43 registry.selector().reregister(fd, token, interests)
44 }
45
46 pub(crate) fn deregister(&mut self, registry: &Registry, fd: RawFd) -> io::Result<()> {
47 // Pass through, we don't have any state.
48 registry.selector().deregister(fd)
49 }
50}
51