@@ -6,7 +6,8 @@ use crate::fs;
66use crate::os::raw;
77use crate::sys;
88use crate::io;
9- use crate::sys_common::{AsInner, FromInner, IntoInner};
9+ use crate::sys_common::{self, AsInner, FromInner, IntoInner};
10+ use crate::net;
1011
1112/// Raw file descriptors.
1213#[stable(feature = "rust1", since = "1.0.0")]
@@ -110,3 +111,61 @@ impl<'a> AsRawFd for io::StdoutLock<'a> {
110111impl<'a> AsRawFd for io::StderrLock<'a> {
111112 fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
112113}
114+
115+ #[stable(feature = "rust1", since = "1.0.0")]
116+ impl AsRawFd for net::TcpStream {
117+ fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
118+ }
119+
120+ #[stable(feature = "rust1", since = "1.0.0")]
121+ impl AsRawFd for net::TcpListener {
122+ fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
123+ }
124+
125+ #[stable(feature = "rust1", since = "1.0.0")]
126+ impl AsRawFd for net::UdpSocket {
127+ fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
128+ }
129+
130+ #[stable(feature = "from_raw_os", since = "1.1.0")]
131+ impl FromRawFd for net::TcpStream {
132+ unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
133+ let socket = sys::net::Socket::from_inner(fd);
134+ net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
135+ }
136+ }
137+
138+ #[stable(feature = "from_raw_os", since = "1.1.0")]
139+ impl FromRawFd for net::TcpListener {
140+ unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
141+ let socket = sys::net::Socket::from_inner(fd);
142+ net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
143+ }
144+ }
145+
146+ #[stable(feature = "from_raw_os", since = "1.1.0")]
147+ impl FromRawFd for net::UdpSocket {
148+ unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
149+ let socket = sys::net::Socket::from_inner(fd);
150+ net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
151+ }
152+ }
153+
154+ #[stable(feature = "into_raw_os", since = "1.4.0")]
155+ impl IntoRawFd for net::TcpStream {
156+ fn into_raw_fd(self) -> RawFd {
157+ self.into_inner().into_socket().into_inner()
158+ }
159+ }
160+ #[stable(feature = "into_raw_os", since = "1.4.0")]
161+ impl IntoRawFd for net::TcpListener {
162+ fn into_raw_fd(self) -> RawFd {
163+ self.into_inner().into_socket().into_inner()
164+ }
165+ }
166+ #[stable(feature = "into_raw_os", since = "1.4.0")]
167+ impl IntoRawFd for net::UdpSocket {
168+ fn into_raw_fd(self) -> RawFd {
169+ self.into_inner().into_socket().into_inner()
170+ }
171+ }
0 commit comments