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.
This commit is contained in:
parent
4fc3765c54
commit
2ccaeff582
2 changed files with 62 additions and 59 deletions
|
@ -13,11 +13,10 @@
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
use fs;
|
use fs;
|
||||||
use net;
|
|
||||||
use os::raw;
|
use os::raw;
|
||||||
use sys;
|
use sys;
|
||||||
use io;
|
use io;
|
||||||
use sys_common::{self, AsInner, FromInner, IntoInner};
|
use sys_common::{AsInner, FromInner, IntoInner};
|
||||||
use libc;
|
use libc;
|
||||||
|
|
||||||
/// Raw file descriptors.
|
/// Raw file descriptors.
|
||||||
|
@ -93,19 +92,6 @@ impl IntoRawFd for fs::File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl AsRawFd for net::TcpStream {
|
|
||||||
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
|
|
||||||
}
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl AsRawFd for net::TcpListener {
|
|
||||||
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
|
|
||||||
}
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
|
||||||
impl AsRawFd for net::UdpSocket {
|
|
||||||
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
#[stable(feature = "asraw_stdio", since = "1.21.0")]
|
||||||
impl AsRawFd for io::Stdin {
|
impl AsRawFd for io::Stdin {
|
||||||
fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO }
|
fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO }
|
||||||
|
@ -120,44 +106,3 @@ impl AsRawFd for io::Stdout {
|
||||||
impl AsRawFd for io::Stderr {
|
impl AsRawFd for io::Stderr {
|
||||||
fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
|
fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
|
||||||
impl FromRawFd for net::TcpStream {
|
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
|
|
||||||
let socket = sys::net::Socket::from_inner(fd);
|
|
||||||
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
|
||||||
impl FromRawFd for net::TcpListener {
|
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
|
|
||||||
let socket = sys::net::Socket::from_inner(fd);
|
|
||||||
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
|
||||||
impl FromRawFd for net::UdpSocket {
|
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
|
|
||||||
let socket = sys::net::Socket::from_inner(fd);
|
|
||||||
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
|
||||||
impl IntoRawFd for net::TcpStream {
|
|
||||||
fn into_raw_fd(self) -> RawFd {
|
|
||||||
self.into_inner().into_socket().into_inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
|
||||||
impl IntoRawFd for net::TcpListener {
|
|
||||||
fn into_raw_fd(self) -> RawFd {
|
|
||||||
self.into_inner().into_socket().into_inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
|
||||||
impl IntoRawFd for net::UdpSocket {
|
|
||||||
fn into_raw_fd(self) -> RawFd {
|
|
||||||
self.into_inner().into_socket().into_inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,14 +30,14 @@ use ffi::OsStr;
|
||||||
use fmt;
|
use fmt;
|
||||||
use io::{self, Initializer};
|
use io::{self, Initializer};
|
||||||
use mem;
|
use mem;
|
||||||
use net::Shutdown;
|
use net::{self, Shutdown};
|
||||||
use os::unix::ffi::OsStrExt;
|
use os::unix::ffi::OsStrExt;
|
||||||
use os::unix::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd};
|
use os::unix::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd};
|
||||||
use path::Path;
|
use path::Path;
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
use sys::cvt;
|
use sys::{self, cvt};
|
||||||
use sys::net::Socket;
|
use sys::net::Socket;
|
||||||
use sys_common::{AsInner, FromInner, IntoInner};
|
use sys_common::{self, AsInner, FromInner, IntoInner};
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android",
|
#[cfg(any(target_os = "linux", target_os = "android",
|
||||||
target_os = "dragonfly", target_os = "freebsd",
|
target_os = "dragonfly", target_os = "freebsd",
|
||||||
|
@ -588,6 +588,64 @@ impl IntoRawFd for UnixStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl AsRawFd for net::TcpStream {
|
||||||
|
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl AsRawFd for net::TcpListener {
|
||||||
|
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl AsRawFd for net::UdpSocket {
|
||||||
|
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||||
|
impl FromRawFd for net::TcpStream {
|
||||||
|
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
|
||||||
|
let socket = sys::net::Socket::from_inner(fd);
|
||||||
|
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||||
|
impl FromRawFd for net::TcpListener {
|
||||||
|
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
|
||||||
|
let socket = sys::net::Socket::from_inner(fd);
|
||||||
|
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||||
|
impl FromRawFd for net::UdpSocket {
|
||||||
|
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
|
||||||
|
let socket = sys::net::Socket::from_inner(fd);
|
||||||
|
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
||||||
|
impl IntoRawFd for net::TcpStream {
|
||||||
|
fn into_raw_fd(self) -> RawFd {
|
||||||
|
self.into_inner().into_socket().into_inner()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
||||||
|
impl IntoRawFd for net::TcpListener {
|
||||||
|
fn into_raw_fd(self) -> RawFd {
|
||||||
|
self.into_inner().into_socket().into_inner()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
||||||
|
impl IntoRawFd for net::UdpSocket {
|
||||||
|
fn into_raw_fd(self) -> RawFd {
|
||||||
|
self.into_inner().into_socket().into_inner()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A structure representing a Unix domain socket server.
|
/// A structure representing a Unix domain socket server.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue