1pub use rustix::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
2
3macro_rules! rustix_fn {
4 ($fn:ident($name:ident(
5 $($field_name:ident: $field_ty:ty),*
6 ) -> $return_ty:ty)) => {
7 #[inline]
8 pub(super) fn $name<T>(this: &T, $($field_name: $field_ty,)*) -> ::std::io::Result<$return_ty>
9 where
10 T: AsFd,
11 {
12 ::rustix::net::sockopt::$fn(this, $($field_name,)*)
13 .map_err(|e| ::std::io::Error::from_raw_os_error(e.raw_os_error()))
14 }
15 };
16}
17
18rustix_fn!(ipv6_v6only(only_v6() -> bool));
19rustix_fn!(set_socket_recv_buffer_size(set_recv_buffer_size(size: usize) -> ()));
20rustix_fn!(socket_recv_buffer_size(recv_buffer_size() -> usize));
21rustix_fn!(set_socket_send_buffer_size(set_send_buffer_size(size: usize) -> ()));
22rustix_fn!(socket_send_buffer_size(send_buffer_size() -> usize));
23rustix_fn!(set_socket_linger(set_linger(duration: Option<std::time::Duration>) -> ()));
24rustix_fn!(socket_linger(linger() -> Option<std::time::Duration>));
25
26pub(super) fn shutdown<T>(this: &T, how: std::net::Shutdown) -> std::io::Result<()>
27where
28 T: AsFd,
29{
30 rustix::net::shutdown(
31 this,
32 match how {
33 std::net::Shutdown::Read => rustix::net::Shutdown::Read,
34 std::net::Shutdown::Write => rustix::net::Shutdown::Write,
35 std::net::Shutdown::Both => rustix::net::Shutdown::Both,
36 },
37 )
38 .map_err(|e| std::io::Error::from_raw_os_error(e.raw_os_error()))
39}
40
41pub(super) fn duplicate<T, O>(this: &T) -> std::io::Result<O>
42where
43 T: AsFd,
44 O: FromRawFd,
45{
46 rustix::io::dup(this)
47 .map(|fd| unsafe { O::from_raw_fd(fd.into_raw_fd()) })
48 .map_err(|e| std::io::Error::from_raw_os_error(e.raw_os_error()))
49}