@@ -80,3 +80,68 @@ cfg_not_os_poll! {
80
80
pub use self :: unix:: SourceFd ;
81
81
}
82
82
}
83
+
84
+ /// Define the `listen` backlog parameters as in the standard library. This
85
+ /// helps avoid hardcoded unsynchronized values and allows better control of
86
+ /// default values depending on the target.
87
+ ///
88
+ /// Selecting a “valid” default value can be tricky due to:
89
+ ///
90
+ /// - It often serves only as a hint and may be rounded, trimmed, or ignored by
91
+ /// the OS.
92
+ ///
93
+ /// - It is sometimes provided as a "magic" value, for example, -1. This
94
+ /// value is undocumented and not standard, but it is often used to represent
95
+ /// the largest possible backlog size. This happens due to signed/unsigned
96
+ /// conversion and rounding to the upper bound performed by the OS.
97
+ ///
98
+ /// - Default values vary depending on the OS and its version. Common defaults
99
+ /// include: -1, 128, 1024, and 4096.
100
+ ///
101
+ // Here is the original code from the standard library
102
+ // https://github.com/rust-lang/rust/blob/4f808ba6bf9f1c8dde30d009e73386d984491587/library/std/src/os/unix/net/listener.rs#L72
103
+ //
104
+ #[ allow( dead_code) ]
105
+ #[ cfg( any(
106
+ target_os = "windows" ,
107
+ target_os = "redox" ,
108
+ target_os = "espidf" ,
109
+ target_os = "horizon"
110
+ ) ) ]
111
+ pub ( crate ) const LISTEN_BACKLOG_SIZE : i32 = 128 ;
112
+
113
+ /// This is a special case for some target(s) supported by `mio`. This value
114
+ /// is needed because `libc::SOMAXCON` (used as a fallback for unknown targets)
115
+ /// is not implemented for them. Feel free to update this if the `libc` crate
116
+ /// changes.
117
+ #[ allow( dead_code) ]
118
+ #[ cfg( target_os = "hermit" ) ]
119
+ pub ( crate ) const LISTEN_BACKLOG_SIZE : i32 = 1024 ;
120
+
121
+ #[ allow( dead_code) ]
122
+ #[ cfg( any(
123
+ // Silently capped to `/proc/sys/net/core/somaxconn`.
124
+ target_os = "linux" ,
125
+ // Silently capped to `kern.ipc.soacceptqueue`.
126
+ target_os = "freebsd" ,
127
+ // Silently capped to `kern.somaxconn sysctl`.
128
+ target_os = "openbsd" ,
129
+ // Silently capped to the default 128.
130
+ target_vendor = "apple" ,
131
+ ) ) ]
132
+ pub ( crate ) const LISTEN_BACKLOG_SIZE : i32 = -1 ;
133
+
134
+ #[ allow( dead_code) ]
135
+ #[ cfg( not( any(
136
+ target_os = "windows" ,
137
+ target_os = "redox" ,
138
+ target_os = "espidf" ,
139
+ target_os = "horizon" ,
140
+ target_os = "linux" ,
141
+ target_os = "freebsd" ,
142
+ target_os = "openbsd" ,
143
+ target_os = "wasi" ,
144
+ target_os = "hermit" ,
145
+ target_vendor = "apple" ,
146
+ ) ) ) ]
147
+ pub ( crate ) const LISTEN_BACKLOG_SIZE : i32 = libc:: SOMAXCONN ;
0 commit comments