1 | //! Linux and Android-specific socket functionality. |
2 | |
3 | use crate::io; |
4 | use crate::os::unix::net; |
5 | use crate::sealed::Sealed; |
6 | use crate::sys_common::AsInner; |
7 | |
8 | /// Linux-specific functionality for `AF_UNIX` sockets [`UnixDatagram`] |
9 | /// and [`UnixStream`]. |
10 | /// |
11 | /// [`UnixDatagram`]: net::UnixDatagram |
12 | /// [`UnixStream`]: net::UnixStream |
13 | #[unstable (feature = "unix_socket_ancillary_data" , issue = "76915" )] |
14 | pub trait UnixSocketExt: Sealed { |
15 | /// Query the current setting of socket option `SO_PASSCRED`. |
16 | #[unstable (feature = "unix_socket_ancillary_data" , issue = "76915" )] |
17 | fn passcred(&self) -> io::Result<bool>; |
18 | |
19 | /// Enable or disable socket option `SO_PASSCRED`. |
20 | /// |
21 | /// This option enables the credentials of the sending process to be |
22 | /// received as a control message in [`AncillaryData`]. |
23 | /// |
24 | /// [`AncillaryData`]: net::AncillaryData |
25 | /// |
26 | /// # Examples |
27 | /// |
28 | /// ```no_run |
29 | /// #![feature(unix_socket_ancillary_data)] |
30 | /// use std::os::linux::net::UnixSocketExt; |
31 | /// use std::os::unix::net::UnixDatagram; |
32 | /// |
33 | /// fn main() -> std::io::Result<()> { |
34 | /// let sock = UnixDatagram::unbound()?; |
35 | /// sock.set_passcred(true).expect("set_passcred failed" ); |
36 | /// Ok(()) |
37 | /// } |
38 | /// ``` |
39 | #[unstable (feature = "unix_socket_ancillary_data" , issue = "76915" )] |
40 | fn set_passcred(&self, passcred: bool) -> io::Result<()>; |
41 | } |
42 | |
43 | #[unstable (feature = "unix_socket_ancillary_data" , issue = "76915" )] |
44 | impl UnixSocketExt for net::UnixDatagram { |
45 | fn passcred(&self) -> io::Result<bool> { |
46 | self.as_inner().passcred() |
47 | } |
48 | |
49 | fn set_passcred(&self, passcred: bool) -> io::Result<()> { |
50 | self.as_inner().set_passcred(passcred) |
51 | } |
52 | } |
53 | |
54 | #[unstable (feature = "unix_socket_ancillary_data" , issue = "76915" )] |
55 | impl UnixSocketExt for net::UnixStream { |
56 | fn passcred(&self) -> io::Result<bool> { |
57 | self.as_inner().passcred() |
58 | } |
59 | |
60 | fn set_passcred(&self, passcred: bool) -> io::Result<()> { |
61 | self.as_inner().set_passcred(passcred) |
62 | } |
63 | } |
64 | |