diff options
| author | bors <bors@rust-lang.org> | 2014-11-26 08:42:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-11-26 08:42:09 +0000 |
| commit | 61af40278909eb899f1bdfbb8c45d4e4fb3dad5d (patch) | |
| tree | 87d901e82bb5e19ed4e49216f2114c9ca060aee6 /src/libstd/io | |
| parent | 8d7b3199d9a285b66b4f9a49d97234c956cb5e6c (diff) | |
| parent | 1e661642105a1033f1c155ceb1b2335dd11cb40a (diff) | |
| download | rust-61af40278909eb899f1bdfbb8c45d4e4fb3dad5d.tar.gz rust-61af40278909eb899f1bdfbb8c45d4e4fb3dad5d.zip | |
auto merge of #19169 : aturon/rust/fds, r=alexcrichton
This PR adds some internal infrastructure to allow the private `std::sys` module to access internal representation details of `std::io`. It then exposes those details in two new, platform-specific API surfaces: `std::os::unix` and `std::os::windows`. To start with, these will provide the ability to extract file descriptors, HANDLEs, SOCKETs, and so on from `std::io` types. More functionality, and more specific platforms (e.g. `std::os::linux`) will be added over time. Closes #18897
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/fs.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/net/pipe.rs | 20 | ||||
| -rw-r--r-- | src/libstd/io/net/tcp.rs | 20 | ||||
| -rw-r--r-- | src/libstd/io/net/udp.rs | 7 | ||||
| -rw-r--r-- | src/libstd/io/pipe.rs | 4 |
5 files changed, 51 insertions, 4 deletions
diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index cd4141e045c..6d29f3d2538 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -88,8 +88,8 @@ pub struct File { last_nread: int, } -impl sys_common::AsFileDesc for File { - fn as_fd(&self) -> &fs_imp::FileDesc { +impl sys_common::AsInner<fs_imp::FileDesc> for File { + fn as_inner(&self) -> &fs_imp::FileDesc { &self.fd } } diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index 8e934d221d2..2984fa59631 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -33,6 +33,8 @@ use sys::pipe::UnixStream as UnixStreamImp; use sys::pipe::UnixListener as UnixListenerImp; use sys::pipe::UnixAcceptor as UnixAcceptorImp; +use sys_common; + /// A stream which communicates over a named pipe. pub struct UnixStream { inner: UnixStreamImp, @@ -145,6 +147,12 @@ impl Writer for UnixStream { } } +impl sys_common::AsInner<UnixStreamImp> for UnixStream { + fn as_inner(&self) -> &UnixStreamImp { + &self.inner + } +} + /// A value that can listen for incoming named pipe connection requests. pub struct UnixListener { /// The internal, opaque runtime Unix listener. @@ -186,6 +194,12 @@ impl Listener<UnixStream, UnixAcceptor> for UnixListener { } } +impl sys_common::AsInner<UnixListenerImp> for UnixListener { + fn as_inner(&self) -> &UnixListenerImp { + &self.inner + } +} + /// A value that can accept named pipe connections, returned from `listen()`. pub struct UnixAcceptor { /// The internal, opaque runtime Unix acceptor. @@ -247,6 +261,12 @@ impl Clone for UnixAcceptor { } } +impl sys_common::AsInner<UnixAcceptorImp> for UnixAcceptor { + fn as_inner(&self) -> &UnixAcceptorImp { + &self.inner + } +} + #[cfg(test)] #[allow(experimental)] mod tests { diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index cbac6b48b83..a989be758c3 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -31,6 +31,8 @@ use sys::tcp::TcpStream as TcpStreamImp; use sys::tcp::TcpListener as TcpListenerImp; use sys::tcp::TcpAcceptor as TcpAcceptorImp; +use sys_common; + /// A structure which represents a TCP stream between a local socket and a /// remote socket. /// @@ -260,6 +262,12 @@ impl Writer for TcpStream { } } +impl sys_common::AsInner<TcpStreamImp> for TcpStream { + fn as_inner(&self) -> &TcpStreamImp { + &self.inner + } +} + /// A structure representing a socket server. This listener is used to create a /// `TcpAcceptor` which can be used to accept sockets on a local port. /// @@ -329,6 +337,12 @@ impl Listener<TcpStream, TcpAcceptor> for TcpListener { } } +impl sys_common::AsInner<TcpListenerImp> for TcpListener { + fn as_inner(&self) -> &TcpListenerImp { + &self.inner + } +} + /// The accepting half of a TCP socket server. This structure is created through /// a `TcpListener`'s `listen` method, and this object can be used to accept new /// `TcpStream` instances. @@ -456,6 +470,12 @@ impl Clone for TcpAcceptor { } } +impl sys_common::AsInner<TcpAcceptorImp> for TcpAcceptor { + fn as_inner(&self) -> &TcpAcceptorImp { + &self.inner + } +} + #[cfg(test)] #[allow(experimental)] mod test { diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 567e7da0c00..a7239ca0f2f 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -21,6 +21,7 @@ use io::{Reader, Writer, IoResult}; use option::Option; use result::{Ok, Err}; use sys::udp::UdpSocket as UdpSocketImp; +use sys_common; /// A User Datagram Protocol socket. /// @@ -184,6 +185,12 @@ impl Clone for UdpSocket { } } +impl sys_common::AsInner<UdpSocketImp> for UdpSocket { + fn as_inner(&self) -> &UdpSocketImp { + &self.inner + } +} + /// A type that allows convenient usage of a UDP stream connected to one /// address via the `Reader` and `Writer` traits. /// diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index 8c20ea08863..41676cdf6e9 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -86,8 +86,8 @@ impl PipeStream { } } -impl sys_common::AsFileDesc for PipeStream { - fn as_fd(&self) -> &sys::fs::FileDesc { +impl sys_common::AsInner<sys::fs::FileDesc> for PipeStream { + fn as_inner(&self) -> &sys::fs::FileDesc { &*self.inner } } |
