Skip to main content

ntex_server/
lib.rs

1#![deny(clippy::pedantic)]
2#![allow(
3    async_fn_in_trait,
4    clippy::clone_on_copy,
5    clippy::must_use_candidate,
6    clippy::missing_fields_in_debug,
7    clippy::missing_errors_doc,
8    clippy::missing_panics_doc,
9    clippy::unused_async
10)]
11
12use ntex_service::Service;
13
14mod manager;
15pub mod net;
16mod pool;
17mod server;
18mod wrk;
19
20pub use self::pool::WorkerPool;
21pub use self::server::Server;
22pub use self::wrk::{Worker, WorkerStatus, WorkerStop};
23
24/// Worker id
25#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
26pub struct WorkerId(pub(crate) usize);
27
28impl WorkerId {
29    pub(self) fn next(&mut self) -> WorkerId {
30        let id = WorkerId(self.0);
31        self.0 += 1;
32        id
33    }
34}
35
36/// Worker service configuration.
37pub trait ServerConfiguration: Send + Clone + 'static {
38    type Item: Send + 'static;
39    type Service: Service<(), Self::Item, Res = (), Error = ()> + 'static;
40
41    /// Create service for handling `WorkerMessage<T>` messages.
42    async fn create(&self) -> std::io::Result<Self::Service>;
43
44    /// Pause the server.
45    fn pause(&self) {}
46
47    /// Resume the server.
48    fn resume(&self) {}
49
50    /// Server is stopped.
51    fn terminate(&self) {}
52
53    /// Server is stopped.
54    async fn stop(&self) {}
55}