]> git.proxmox.com Git - rustc.git/blob - library/std/src/os/unix/net/raw_fd.rs
New upstream version 1.54.0+dfsg1
[rustc.git] / library / std / src / os / unix / net / raw_fd.rs
1 use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
2 use crate::sys_common::{self, AsInner, FromInner, IntoInner};
3 use crate::{net, sys};
4
5 macro_rules! impl_as_raw_fd {
6 ($($t:ident)*) => {$(
7 #[stable(feature = "rust1", since = "1.0.0")]
8 impl AsRawFd for net::$t {
9 #[inline]
10 fn as_raw_fd(&self) -> RawFd {
11 *self.as_inner().socket().as_inner()
12 }
13 }
14 )*};
15 }
16 impl_as_raw_fd! { TcpStream TcpListener UdpSocket }
17
18 macro_rules! impl_from_raw_fd {
19 ($($t:ident)*) => {$(
20 #[stable(feature = "from_raw_os", since = "1.1.0")]
21 impl FromRawFd for net::$t {
22 #[inline]
23 unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
24 let socket = sys::net::Socket::from_inner(fd);
25 net::$t::from_inner(sys_common::net::$t::from_inner(socket))
26 }
27 }
28 )*};
29 }
30 impl_from_raw_fd! { TcpStream TcpListener UdpSocket }
31
32 macro_rules! impl_into_raw_fd {
33 ($($t:ident)*) => {$(
34 #[stable(feature = "into_raw_os", since = "1.4.0")]
35 impl IntoRawFd for net::$t {
36 #[inline]
37 fn into_raw_fd(self) -> RawFd {
38 self.into_inner().into_socket().into_inner()
39 }
40 }
41 )*};
42 }
43 impl_into_raw_fd! { TcpStream TcpListener UdpSocket }