Skip to content

Commit 2ccaeff

Browse files
author
Tobias Schaffner
committed
Refactoring: move net specific fd imps to net
Move the implementations of net specific file descriptior implementations to net. This makes it easier to exclude net at all if not needed for a target.
1 parent 4fc3765 commit 2ccaeff

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

src/libstd/sys/unix/ext/io.rs

+1-56
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

1515
use fs;
16-
use net;
1716
use os::raw;
1817
use sys;
1918
use io;
20-
use sys_common::{self, AsInner, FromInner, IntoInner};
19+
use sys_common::{AsInner, FromInner, IntoInner};
2120
use libc;
2221

2322
/// Raw file descriptors.
@@ -93,19 +92,6 @@ impl IntoRawFd for fs::File {
9392
}
9493
}
9594

96-
#[stable(feature = "rust1", since = "1.0.0")]
97-
impl AsRawFd for net::TcpStream {
98-
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
99-
}
100-
#[stable(feature = "rust1", since = "1.0.0")]
101-
impl AsRawFd for net::TcpListener {
102-
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
103-
}
104-
#[stable(feature = "rust1", since = "1.0.0")]
105-
impl AsRawFd for net::UdpSocket {
106-
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
107-
}
108-
10995
#[stable(feature = "asraw_stdio", since = "1.21.0")]
11096
impl AsRawFd for io::Stdin {
11197
fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO }
@@ -120,44 +106,3 @@ impl AsRawFd for io::Stdout {
120106
impl AsRawFd for io::Stderr {
121107
fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
122108
}
123-
124-
#[stable(feature = "from_raw_os", since = "1.1.0")]
125-
impl FromRawFd for net::TcpStream {
126-
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
127-
let socket = sys::net::Socket::from_inner(fd);
128-
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
129-
}
130-
}
131-
#[stable(feature = "from_raw_os", since = "1.1.0")]
132-
impl FromRawFd for net::TcpListener {
133-
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
134-
let socket = sys::net::Socket::from_inner(fd);
135-
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
136-
}
137-
}
138-
#[stable(feature = "from_raw_os", since = "1.1.0")]
139-
impl FromRawFd for net::UdpSocket {
140-
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
141-
let socket = sys::net::Socket::from_inner(fd);
142-
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
143-
}
144-
}
145-
146-
#[stable(feature = "into_raw_os", since = "1.4.0")]
147-
impl IntoRawFd for net::TcpStream {
148-
fn into_raw_fd(self) -> RawFd {
149-
self.into_inner().into_socket().into_inner()
150-
}
151-
}
152-
#[stable(feature = "into_raw_os", since = "1.4.0")]
153-
impl IntoRawFd for net::TcpListener {
154-
fn into_raw_fd(self) -> RawFd {
155-
self.into_inner().into_socket().into_inner()
156-
}
157-
}
158-
#[stable(feature = "into_raw_os", since = "1.4.0")]
159-
impl IntoRawFd for net::UdpSocket {
160-
fn into_raw_fd(self) -> RawFd {
161-
self.into_inner().into_socket().into_inner()
162-
}
163-
}

src/libstd/sys/unix/ext/net.rs

+61-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ use ffi::OsStr;
3030
use fmt;
3131
use io::{self, Initializer};
3232
use mem;
33-
use net::Shutdown;
33+
use net::{self, Shutdown};
3434
use os::unix::ffi::OsStrExt;
3535
use os::unix::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd};
3636
use path::Path;
3737
use time::Duration;
38-
use sys::cvt;
38+
use sys::{self, cvt};
3939
use sys::net::Socket;
40-
use sys_common::{AsInner, FromInner, IntoInner};
40+
use sys_common::{self, AsInner, FromInner, IntoInner};
4141

4242
#[cfg(any(target_os = "linux", target_os = "android",
4343
target_os = "dragonfly", target_os = "freebsd",
@@ -588,6 +588,64 @@ impl IntoRawFd for UnixStream {
588588
}
589589
}
590590

591+
#[stable(feature = "rust1", since = "1.0.0")]
592+
impl AsRawFd for net::TcpStream {
593+
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
594+
}
595+
596+
#[stable(feature = "rust1", since = "1.0.0")]
597+
impl AsRawFd for net::TcpListener {
598+
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
599+
}
600+
601+
#[stable(feature = "rust1", since = "1.0.0")]
602+
impl AsRawFd for net::UdpSocket {
603+
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
604+
}
605+
606+
#[stable(feature = "from_raw_os", since = "1.1.0")]
607+
impl FromRawFd for net::TcpStream {
608+
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
609+
let socket = sys::net::Socket::from_inner(fd);
610+
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
611+
}
612+
}
613+
614+
#[stable(feature = "from_raw_os", since = "1.1.0")]
615+
impl FromRawFd for net::TcpListener {
616+
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
617+
let socket = sys::net::Socket::from_inner(fd);
618+
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
619+
}
620+
}
621+
622+
#[stable(feature = "from_raw_os", since = "1.1.0")]
623+
impl FromRawFd for net::UdpSocket {
624+
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
625+
let socket = sys::net::Socket::from_inner(fd);
626+
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
627+
}
628+
}
629+
630+
#[stable(feature = "into_raw_os", since = "1.4.0")]
631+
impl IntoRawFd for net::TcpStream {
632+
fn into_raw_fd(self) -> RawFd {
633+
self.into_inner().into_socket().into_inner()
634+
}
635+
}
636+
#[stable(feature = "into_raw_os", since = "1.4.0")]
637+
impl IntoRawFd for net::TcpListener {
638+
fn into_raw_fd(self) -> RawFd {
639+
self.into_inner().into_socket().into_inner()
640+
}
641+
}
642+
#[stable(feature = "into_raw_os", since = "1.4.0")]
643+
impl IntoRawFd for net::UdpSocket {
644+
fn into_raw_fd(self) -> RawFd {
645+
self.into_inner().into_socket().into_inner()
646+
}
647+
}
648+
591649
/// A structure representing a Unix domain socket server.
592650
///
593651
/// # Examples

0 commit comments

Comments
 (0)