1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// This file was automatically generated by `elaborate`.
// https://github.com/trailofbits/elaborate
#[allow(unused_imports)]
use anyhow::Context;
#[cfg(target_os = "linux")]
pub trait SocketAddrExtContext: std :: os :: linux :: net :: SocketAddrExt {
/// Creates a Unix socket address in the abstract namespace.
///
/// The abstract namespace is a Linux-specific extension that allows Unix
/// sockets to be bound without creating an entry in the filesystem.
/// Abstract sockets are unaffected by filesystem layout or permissions,
/// and no cleanup is necessary when the socket is closed.
///
/// An abstract socket address name may contain any bytes, including zero.
///
/// # Errors
///
/// Returns an error if the name is longer than `SUN_LEN - 1`.
///
/// # Examples
///
/// ```no_run
/// use std::os::unix::net::{UnixListener, SocketAddr};
/// #[cfg(target_os = "linux")]
/// use std::os::linux::net::SocketAddrExt;
/// #[cfg(target_os = "android")]
/// use std::os::android::net::SocketAddrExt;
///
/// fn main() -> std::io::Result<()> {
/// let addr = SocketAddr::from_abstract_name(b"hidden")?;
/// let listener = match UnixListener::bind_addr(&addr) {
/// Ok(sock) => sock,
/// Err(err) => {
/// println!("Couldn't bind: {err:?}");
/// return Err(err);
/// }
/// };
/// Ok(())
/// }
/// ```
#[cfg(unix)]
fn from_abstract_name_wc < N > ( name : N ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: os :: unix :: net :: SocketAddr > ) where N : core :: convert :: AsRef < [ u8 ] > {
let name = name.as_ref();
< Self as :: std :: os :: linux :: net :: SocketAddrExt > :: from_abstract_name(name)
.with_context(|| crate::call_failed!(None::<()>, "< Self as :: std :: os :: linux :: net :: SocketAddrExt > :: from_abstract_name", name))
}
/// Returns the contents of this address if it is in the abstract namespace.
///
/// # Examples
///
/// ```no_run
/// use std::os::unix::net::{UnixListener, SocketAddr};
/// #[cfg(target_os = "linux")]
/// use std::os::linux::net::SocketAddrExt;
/// #[cfg(target_os = "android")]
/// use std::os::android::net::SocketAddrExt;
///
/// fn main() -> std::io::Result<()> {
/// let name = b"hidden";
/// let name_addr = SocketAddr::from_abstract_name(name)?;
/// let socket = UnixListener::bind_addr(&name_addr)?;
/// let local_addr = socket.local_addr().expect("Couldn't get local address");
/// assert_eq!(local_addr.as_abstract_name(), Some(&name[..]));
/// Ok(())
/// }
/// ```
fn as_abstract_name_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & [ u8 ] > ) {
< Self as :: std :: os :: linux :: net :: SocketAddrExt > :: as_abstract_name(self)
.with_context(|| crate::call_failed!(Some(self), "as_abstract_name"))
}
}
#[cfg(target_os = "linux")]
impl<T> SocketAddrExtContext for T where T: std :: os :: linux :: net :: SocketAddrExt {}
#[cfg(target_os = "linux")]
pub trait TcpStreamExtContext: std :: os :: linux :: net :: TcpStreamExt {
/// A socket listener will be awakened solely when data arrives.
///
/// The `accept` argument set the maximum delay until the
/// data is available to read, reducing the number of short lived
/// connections without data to process.
/// Contrary to other platforms `SO_ACCEPTFILTER` feature equivalent, there is
/// no necessity to set it after the `listen` call.
/// Note that the delay is expressed as Duration from user's perspective
/// the call rounds it down to the nearest second expressible as a `c_int`.
///
/// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html)
///
/// # Examples
///
/// ```no run
/// #![feature(tcp_deferaccept)]
/// use std::net::TcpStream;
/// use std::os::linux::net::TcpStreamExt;
/// use std::time::Duration;
///
/// let stream = TcpStream::connect("127.0.0.1:8080")
/// .expect("Couldn't connect to the server...");
/// stream.set_deferaccept(Duration::from_secs(1u64)).expect("set_deferaccept call failed");
/// ```
#[cfg(feature = "tcp_deferaccept")]
fn set_deferaccept_wc ( & self , accept : core :: time :: Duration ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
< Self as :: std :: os :: linux :: net :: TcpStreamExt > :: set_deferaccept(self, accept)
.with_context(|| crate::call_failed!(Some(self), "set_deferaccept", accept))
}
/// Enable or disable `TCP_QUICKACK`.
///
/// This flag causes Linux to eagerly send ACKs rather than delaying them.
/// Linux may reset this flag after further operations on the socket.
///
/// See [`man 7 tcp`](https://man7.org/linux/man-pages/man7/tcp.7.html) and
/// [TCP delayed acknowledgement](https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment)
/// for more information.
///
/// # Examples
///
/// ```no_run
/// use std::net::TcpStream;
/// #[cfg(target_os = "linux")]
/// use std::os::linux::net::TcpStreamExt;
/// #[cfg(target_os = "android")]
/// use std::os::android::net::TcpStreamExt;
///
/// let stream = TcpStream::connect("127.0.0.1:8080")
/// .expect("Couldn't connect to the server...");
/// stream.set_quickack(true).expect("set_quickack call failed");
/// ```
fn set_quickack_wc ( & self , quickack : bool ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
< Self as :: std :: os :: linux :: net :: TcpStreamExt > :: set_quickack(self, quickack)
.with_context(|| crate::call_failed!(Some(self), "set_quickack", quickack))
}
/// Gets the accept delay value of the `TCP_DEFER_ACCEPT` option.
///
/// For more information about this option, see [`TcpStreamExt::set_deferaccept`].
///
/// # Examples
///
/// ```no_run
/// #![feature(tcp_deferaccept)]
/// use std::net::TcpStream;
/// use std::os::linux::net::TcpStreamExt;
/// use std::time::Duration;
///
/// let stream = TcpStream::connect("127.0.0.1:8080")
/// .expect("Couldn't connect to the server...");
/// stream.set_deferaccept(Duration::from_secs(1u64)).expect("set_deferaccept call failed");
/// assert_eq!(stream.deferaccept().unwrap(), Duration::from_secs(1u64));
/// ```
#[cfg(feature = "tcp_deferaccept")]
fn deferaccept_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < core :: time :: Duration > ) {
< Self as :: std :: os :: linux :: net :: TcpStreamExt > :: deferaccept(self)
.with_context(|| crate::call_failed!(Some(self), "deferaccept"))
}
/// Gets the value of the `TCP_QUICKACK` option on this socket.
///
/// For more information about this option, see [`TcpStreamExt::set_quickack`].
///
/// # Examples
///
/// ```no_run
/// use std::net::TcpStream;
/// #[cfg(target_os = "linux")]
/// use std::os::linux::net::TcpStreamExt;
/// #[cfg(target_os = "android")]
/// use std::os::android::net::TcpStreamExt;
///
/// let stream = TcpStream::connect("127.0.0.1:8080")
/// .expect("Couldn't connect to the server...");
/// stream.set_quickack(true).expect("set_quickack call failed");
/// assert_eq!(stream.quickack().unwrap_or(false), true);
/// ```
fn quickack_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < bool > ) {
< Self as :: std :: os :: linux :: net :: TcpStreamExt > :: quickack(self)
.with_context(|| crate::call_failed!(Some(self), "quickack"))
}
}
#[cfg(target_os = "linux")]
impl<T> TcpStreamExtContext for T where T: std :: os :: linux :: net :: TcpStreamExt {}
#[cfg(feature = "unix_socket_ancillary_data")]
#[cfg(target_os = "linux")]
pub trait UnixSocketExtContext: std :: os :: linux :: net :: UnixSocketExt {
/// Enable or disable socket option `SO_PASSCRED`.
///
/// This option enables the credentials of the sending process to be
/// received as a control message in [`AncillaryData`].
///
/// [`AncillaryData`]: net::AncillaryData
///
/// # Examples
///
/// ```no_run
/// #![feature(unix_socket_ancillary_data)]
/// #[cfg(target_os = "linux")]
/// use std::os::linux::net::UnixSocketExt;
/// #[cfg(target_os = "android")]
/// use std::os::android::net::UnixSocketExt;
/// use std::os::unix::net::UnixDatagram;
///
/// fn main() -> std::io::Result<()> {
/// let sock = UnixDatagram::unbound()?;
/// sock.set_passcred(true).expect("set_passcred failed");
/// Ok(())
/// }
/// ```
fn set_passcred_wc ( & self , passcred : bool ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
< Self as :: std :: os :: linux :: net :: UnixSocketExt > :: set_passcred(self, passcred)
.with_context(|| crate::call_failed!(Some(self), "set_passcred", passcred))
}
/// Query the current setting of socket option `SO_PASSCRED`.
fn passcred_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < bool > ) {
< Self as :: std :: os :: linux :: net :: UnixSocketExt > :: passcred(self)
.with_context(|| crate::call_failed!(Some(self), "passcred"))
}
}
#[cfg(feature = "unix_socket_ancillary_data")]
#[cfg(target_os = "linux")]
impl<T> UnixSocketExtContext for T where T: std :: os :: linux :: net :: UnixSocketExt {}