ntex_net/polling/mod.rs
1mod accept;
2mod connect;
3mod io;
4mod reactor;
5mod stream;
6
7pub use self::reactor::{Handler, Reactor, ReactorApi};
8pub use ::ntex_polling::{Event, PollMode};
9
10#[cfg(not(target_pointer_width = "64"))]
11compile_error!("Only 64bit platforms are supported");
12
13/// Slab slot of a registration and the generation of the registration in it.
14///
15/// The reactor runs tasks between chunks of the events of one poll. A task
16/// can release a slot and a new registration can reuse it while events of the
17/// old one are still queued, the generation keeps them from reaching the new
18/// registration.
19#[derive(Copy, Clone, Debug, PartialEq, Eq)]
20struct Key {
21 idx: u32,
22 generation: u16,
23}
24
25impl Key {
26 const fn new(idx: u32, generation: u16) -> Self {
27 Key { idx, generation }
28 }
29
30 /// Id passed to `ReactorApi`
31 fn id(self) -> u64 {
32 u64::from(self.idx) | (u64::from(self.generation) << 32)
33 }
34
35 /// Key of an id passed to a `Handler`
36 #[allow(clippy::cast_possible_truncation)]
37 const fn from_id(id: usize) -> Self {
38 Key {
39 idx: id as u32,
40 generation: (id >> 32) as u16,
41 }
42 }
43}
44
45/// Tcp stream wrapper for neon `TcpStream`
46///
47/// The flag tells whether the socket is still attached to the reactor by the
48/// connect that opened it.
49struct TcpStream(socket2::Socket, stream::StreamOps, bool);
50
51/// Tcp stream wrapper for neon `UnixStream`
52///
53/// The flag tells whether the socket is still attached to the reactor by the
54/// connect that opened it.
55struct UnixStream(socket2::Socket, stream::StreamOps, bool);