tokio_listener/
options.rs

1#[cfg_attr(feature = "clap", derive(clap::Args))]
2#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
3#[allow(clippy::struct_excessive_bools, clippy::doc_markdown)]
4#[derive(Debug, Default)]
5#[non_exhaustive]
6/// User options that supplement listening address.
7///
8/// With `clap` crate feature, this struct can be `clap(flatten)`-ed directly into your primary command line parameters.
9/// With `serde` crate feature, it supportes serialisation and deserialisation.
10///
11/// Create instances with `Default::default()` and modify available fields.
12///
13/// Non-relevant options are ignored by [`Listener::bind`].
14///
15/// All options are always available regardless of current platform, but may be hidden from --help.
16///
17/// Disabling related crate features removes them for good though.
18pub struct UserOptions {
19    #[cfg(feature = "unix_path_tools")]
20    #[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
21    /// remove UNIX socket prior to binding to it
22    #[cfg_attr(feature = "clap", clap(long))]
23    #[cfg_attr(feature = "serde", serde(default))]
24    #[cfg_attr(all(feature = "clap", not(unix)), clap(hide = true))]
25    pub unix_listen_unlink: bool,
26
27    #[cfg(feature = "unix_path_tools")]
28    #[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
29    /// change filesystem mode of the newly bound UNIX socket to `owner`, `group` or `everybody`
30    #[cfg_attr(feature = "clap", clap(long))]
31    #[cfg_attr(all(feature = "clap", not(unix)), clap(hide = true))]
32    #[cfg_attr(feature = "serde", serde(default))]
33    pub unix_listen_chmod: Option<crate::UnixChmodVariant>,
34
35    #[cfg(feature = "unix_path_tools")]
36    #[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
37    /// change owner user of the newly bound UNIX socket to this numeric uid
38    #[cfg_attr(feature = "clap", clap(long))]
39    #[cfg_attr(feature = "serde", serde(default))]
40    #[cfg_attr(all(feature = "clap", not(unix)), clap(hide = true))]
41    pub unix_listen_uid: Option<u32>,
42
43    #[cfg(feature = "unix_path_tools")]
44    #[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
45    /// change owner group of the newly bound UNIX socket to this numeric uid
46    #[cfg_attr(feature = "clap", clap(long))]
47    #[cfg_attr(feature = "serde", serde(default))]
48    #[cfg_attr(all(feature = "clap", not(unix)), clap(hide = true))]
49    pub unix_listen_gid: Option<u32>,
50
51    #[cfg(feature = "sd_listen")]
52    #[cfg_attr(docsrs_alt, doc(cfg(feature = "sd_listen")))]
53    /// ignore environment variables like LISTEN_PID or LISTEN_FDS and unconditionally use
54    /// file descritor `3` as a socket in sd-listen or sd-listen-unix modes
55    #[cfg_attr(feature = "clap", clap(long))]
56    #[cfg_attr(feature = "serde", serde(default))]
57    #[cfg_attr(all(feature = "clap", not(unix)), clap(hide = true))]
58    pub sd_accept_ignore_environment: bool,
59
60    #[cfg(feature = "socket_options")]
61    #[cfg_attr(docsrs_alt, doc(cfg(feature = "socket_options")))]
62    /// set SO_KEEPALIVE settings for each accepted TCP connection.
63    ///
64    /// Value is a colon-separated triplet of time_ms:count:interval_ms, each of which is optional.
65    #[cfg_attr(feature = "clap", clap(long))]
66    #[cfg_attr(feature = "serde", serde(default))]
67    pub tcp_keepalive: Option<crate::TcpKeepaliveParams>,
68
69    #[cfg(feature = "socket_options")]
70    #[cfg_attr(docsrs_alt, doc(cfg(feature = "socket_options")))]
71    /// Try to set SO_REUSEPORT, so that multiple processes can accept connections from the same port
72    /// in a round-robin fashion
73    #[cfg_attr(feature = "clap", clap(long))]
74    #[cfg_attr(feature = "serde", serde(default))]
75    pub tcp_reuse_port: bool,
76
77    #[cfg(feature = "socket_options")]
78    #[cfg_attr(docsrs_alt, doc(cfg(feature = "socket_options")))]
79    /// Set socket's SO_RCVBUF value.
80    #[cfg_attr(feature = "clap", clap(long))]
81    #[cfg_attr(feature = "serde", serde(default))]
82    pub recv_buffer_size: Option<usize>,
83
84    #[cfg(feature = "socket_options")]
85    #[cfg_attr(docsrs_alt, doc(cfg(feature = "socket_options")))]
86    /// Set socket's SO_SNDBUF value.
87    #[cfg_attr(feature = "clap", clap(long))]
88    #[cfg_attr(feature = "serde", serde(default))]
89    pub send_buffer_size: Option<usize>,
90
91    #[cfg(feature = "socket_options")]
92    #[cfg_attr(docsrs_alt, doc(cfg(feature = "socket_options")))]
93    /// Set socket's IPV6_V6ONLY to true, to avoid receiving IPv4 connections on IPv6 socket.
94    #[cfg_attr(feature = "clap", clap(long))]
95    #[cfg_attr(feature = "serde", serde(default))]
96    pub tcp_only_v6: bool,
97
98    #[cfg(feature = "socket_options")]
99    #[cfg_attr(docsrs_alt, doc(cfg(feature = "socket_options")))]
100    /// Maximum number of pending unaccepted connections
101    #[cfg_attr(feature = "clap", clap(long))]
102    #[cfg_attr(feature = "serde", serde(default))]
103    pub tcp_listen_backlog: Option<u32>,
104}
105
106/// Listener options that are supposed to be hard coded in the code
107/// (not configurable by user)
108#[non_exhaustive]
109#[derive(Debug, Default, Clone, Copy)]
110pub struct SystemOptions {
111    /// Wait for one second and retry if accepting connections fail (for reasons unrelated to the connections themselves),
112    /// assuming it is file descriptor number exhaustion, which may be temporary
113    pub sleep_on_errors: bool,
114
115    /// Set TCP_NODELAY on accepted TCP sockets. Does not affect other socket types.
116    ///
117    /// This field is available even without `socket_options` crate feature.
118    pub nodelay: bool,
119}