aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/sys/redox/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ctr-std/src/sys/redox/ext')
-rw-r--r--ctr-std/src/sys/redox/ext/ffi.rs65
-rw-r--r--ctr-std/src/sys/redox/ext/fs.rs349
-rw-r--r--ctr-std/src/sys/redox/ext/io.rs167
-rw-r--r--ctr-std/src/sys/redox/ext/mod.rs55
-rw-r--r--ctr-std/src/sys/redox/ext/net.rs769
-rw-r--r--ctr-std/src/sys/redox/ext/process.rs187
-rw-r--r--ctr-std/src/sys/redox/ext/thread.rs49
7 files changed, 0 insertions, 1641 deletions
diff --git a/ctr-std/src/sys/redox/ext/ffi.rs b/ctr-std/src/sys/redox/ext/ffi.rs
deleted file mode 100644
index cd88c8f..0000000
--- a/ctr-std/src/sys/redox/ext/ffi.rs
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Redox-specific extension to the primitives in the `std::ffi` module.
-
-#![stable(feature = "rust1", since = "1.0.0")]
-
-use ffi::{OsStr, OsString};
-use mem;
-use sys::os_str::Buf;
-use sys_common::{FromInner, IntoInner, AsInner};
-
-/// Redox-specific extensions to [`OsString`].
-///
-/// [`OsString`]: ../../../../std/ffi/struct.OsString.html
-#[stable(feature = "rust1", since = "1.0.0")]
-pub trait OsStringExt {
- /// Creates an `OsString` from a byte vector.
- #[stable(feature = "rust1", since = "1.0.0")]
- fn from_vec(vec: Vec<u8>) -> Self;
-
- /// Yields the underlying byte vector of this `OsString`.
- #[stable(feature = "rust1", since = "1.0.0")]
- fn into_vec(self) -> Vec<u8>;
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl OsStringExt for OsString {
- fn from_vec(vec: Vec<u8>) -> OsString {
- FromInner::from_inner(Buf { inner: vec })
- }
- fn into_vec(self) -> Vec<u8> {
- self.into_inner().inner
- }
-}
-
-/// Redox-specific extensions to [`OsStr`].
-///
-/// [`OsStr`]: ../../../../std/ffi/struct.OsStr.html
-#[stable(feature = "rust1", since = "1.0.0")]
-pub trait OsStrExt {
- #[stable(feature = "rust1", since = "1.0.0")]
- fn from_bytes(slice: &[u8]) -> &Self;
-
- /// Gets the underlying byte view of the `OsStr` slice.
- #[stable(feature = "rust1", since = "1.0.0")]
- fn as_bytes(&self) -> &[u8];
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl OsStrExt for OsStr {
- fn from_bytes(slice: &[u8]) -> &OsStr {
- unsafe { mem::transmute(slice) }
- }
- fn as_bytes(&self) -> &[u8] {
- &self.as_inner().inner
- }
-}
diff --git a/ctr-std/src/sys/redox/ext/fs.rs b/ctr-std/src/sys/redox/ext/fs.rs
deleted file mode 100644
index c1dba6e..0000000
--- a/ctr-std/src/sys/redox/ext/fs.rs
+++ /dev/null
@@ -1,349 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Redox-specific extensions to primitives in the `std::fs` module.
-
-#![stable(feature = "rust1", since = "1.0.0")]
-
-use fs::{self, Permissions, OpenOptions};
-use io;
-use path::Path;
-use sys;
-use sys_common::{FromInner, AsInner, AsInnerMut};
-
-/// Redox-specific extensions to [`fs::Permissions`].
-///
-/// [`fs::Permissions`]: ../../../../std/fs/struct.Permissions.html
-#[stable(feature = "fs_ext", since = "1.1.0")]
-pub trait PermissionsExt {
- /// Returns the underlying raw `mode_t` bits that are the standard Redox
- /// permissions for this file.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::fs::File;
- /// use std::os::redox::fs::PermissionsExt;
- ///
- /// fn main() -> std::io::Result<()> {
- /// let f = File::create("foo.txt")?;
- /// let metadata = f.metadata()?;
- /// let permissions = metadata.permissions();
- ///
- /// println!("permissions: {}", permissions.mode());
- /// Ok(())
- /// }
- /// ```
- #[stable(feature = "fs_ext", since = "1.1.0")]
- fn mode(&self) -> u32;
-
- /// Sets the underlying raw bits for this set of permissions.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::fs::File;
- /// use std::os::redox::fs::PermissionsExt;
- ///
- /// fn main() -> std::io::Result<()> {
- /// let f = File::create("foo.txt")?;
- /// let metadata = f.metadata()?;
- /// let mut permissions = metadata.permissions();
- ///
- /// permissions.set_mode(0o644); // Read/write for owner and read for others.
- /// assert_eq!(permissions.mode(), 0o644);
- /// Ok(())
- /// }
- /// ```
- #[stable(feature = "fs_ext", since = "1.1.0")]
- fn set_mode(&mut self, mode: u32);
-
- /// Creates a new instance of `Permissions` from the given set of Redox
- /// permission bits.
- ///
- /// # Examples
- ///
- /// ```
- /// use std::fs::Permissions;
- /// use std::os::redox::fs::PermissionsExt;
- ///
- /// // Read/write for owner and read for others.
- /// let permissions = Permissions::from_mode(0o644);
- /// assert_eq!(permissions.mode(), 0o644);
- /// ```
- #[stable(feature = "fs_ext", since = "1.1.0")]
- fn from_mode(mode: u32) -> Self;
-}
-
-#[stable(feature = "fs_ext", since = "1.1.0")]
-impl PermissionsExt for Permissions {
- fn mode(&self) -> u32 {
- self.as_inner().mode()
- }
-
- fn set_mode(&mut self, mode: u32) {
- *self = Permissions::from_inner(FromInner::from_inner(mode));
- }
-
- fn from_mode(mode: u32) -> Permissions {
- Permissions::from_inner(FromInner::from_inner(mode))
- }
-}
-
-/// Redox-specific extensions to [`fs::OpenOptions`].
-///
-/// [`fs::OpenOptions`]: ../../../../std/fs/struct.OpenOptions.html
-#[stable(feature = "fs_ext", since = "1.1.0")]
-pub trait OpenOptionsExt {
- /// Sets the mode bits that a new file will be created with.
- ///
- /// If a new file is created as part of a `File::open_opts` call then this
- /// specified `mode` will be used as the permission bits for the new file.
- /// If no `mode` is set, the default of `0o666` will be used.
- /// The operating system masks out bits with the systems `umask`, to produce
- /// the final permissions.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// # #![feature(libc)]
- /// extern crate libc;
- /// use std::fs::OpenOptions;
- /// use std::os::redox::fs::OpenOptionsExt;
- ///
- /// # fn main() {
- /// let mut options = OpenOptions::new();
- /// options.mode(0o644); // Give read/write for owner and read for others.
- /// let file = options.open("foo.txt");
- /// # }
- /// ```
- #[stable(feature = "fs_ext", since = "1.1.0")]
- fn mode(&mut self, mode: u32) -> &mut Self;
-
- /// Pass custom flags to the `flags` argument of `open`.
- ///
- /// The bits that define the access mode are masked out with `O_ACCMODE`, to
- /// ensure they do not interfere with the access mode set by Rusts options.
- ///
- /// Custom flags can only set flags, not remove flags set by Rusts options.
- /// This options overwrites any previously set custom flags.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// # #![feature(libc)]
- /// extern crate libc;
- /// use std::fs::OpenOptions;
- /// use std::os::redox::fs::OpenOptionsExt;
- ///
- /// # fn main() {
- /// let mut options = OpenOptions::new();
- /// options.write(true);
- /// if cfg!(target_os = "redox") {
- /// options.custom_flags(libc::O_NOFOLLOW);
- /// }
- /// let file = options.open("foo.txt");
- /// # }
- /// ```
- #[stable(feature = "open_options_ext", since = "1.10.0")]
- fn custom_flags(&mut self, flags: i32) -> &mut Self;
-}
-
-#[stable(feature = "fs_ext", since = "1.1.0")]
-impl OpenOptionsExt for OpenOptions {
- fn mode(&mut self, mode: u32) -> &mut OpenOptions {
- self.as_inner_mut().mode(mode); self
- }
-
- fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions {
- self.as_inner_mut().custom_flags(flags); self
- }
-}
-
-/// Redox-specific extensions to [`fs::Metadata`].
-///
-/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html
-#[stable(feature = "metadata_ext", since = "1.1.0")]
-pub trait MetadataExt {
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn dev(&self) -> u64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn ino(&self) -> u64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn mode(&self) -> u32;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn nlink(&self) -> u64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn uid(&self) -> u32;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn gid(&self) -> u32;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn size(&self) -> u64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn atime(&self) -> i64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn atime_nsec(&self) -> i64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn mtime(&self) -> i64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn mtime_nsec(&self) -> i64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn ctime(&self) -> i64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn ctime_nsec(&self) -> i64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn blksize(&self) -> u64;
- #[stable(feature = "metadata_ext", since = "1.1.0")]
- fn blocks(&self) -> u64;
-}
-
-// Hm, why are there casts here to the returned type, shouldn't the types always
-// be the same? Right you are! Turns out, however, on android at least the types
-// in the raw `stat` structure are not the same as the types being returned. Who
-// knew!
-//
-// As a result to make sure this compiles for all platforms we do the manual
-// casts and rely on manual lowering to `stat` if the raw type is desired.
-#[stable(feature = "metadata_ext", since = "1.1.0")]
-impl MetadataExt for fs::Metadata {
- fn dev(&self) -> u64 {
- self.as_inner().as_inner().st_dev as u64
- }
- fn ino(&self) -> u64 {
- self.as_inner().as_inner().st_ino as u64
- }
- fn mode(&self) -> u32 {
- self.as_inner().as_inner().st_mode as u32
- }
- fn nlink(&self) -> u64 {
- self.as_inner().as_inner().st_nlink as u64
- }
- fn uid(&self) -> u32 {
- self.as_inner().as_inner().st_uid as u32
- }
- fn gid(&self) -> u32 {
- self.as_inner().as_inner().st_gid as u32
- }
- fn size(&self) -> u64 {
- self.as_inner().as_inner().st_size as u64
- }
- fn atime(&self) -> i64 {
- self.as_inner().as_inner().st_atime as i64
- }
- fn atime_nsec(&self) -> i64 {
- self.as_inner().as_inner().st_atime_nsec as i64
- }
- fn mtime(&self) -> i64 {
- self.as_inner().as_inner().st_mtime as i64
- }
- fn mtime_nsec(&self) -> i64 {
- self.as_inner().as_inner().st_mtime_nsec as i64
- }
- fn ctime(&self) -> i64 {
- self.as_inner().as_inner().st_ctime as i64
- }
- fn ctime_nsec(&self) -> i64 {
- self.as_inner().as_inner().st_ctime_nsec as i64
- }
- fn blksize(&self) -> u64 {
- self.as_inner().as_inner().st_blksize as u64
- }
- fn blocks(&self) -> u64 {
- self.as_inner().as_inner().st_blocks as u64
- }
-}
-
-/// Redox-specific extensions for [`FileType`].
-///
-/// Adds support for special Unix file types such as block/character devices,
-/// pipes, and sockets.
-///
-/// [`FileType`]: ../../../../std/fs/struct.FileType.html
-#[stable(feature = "file_type_ext", since = "1.5.0")]
-pub trait FileTypeExt {
- /// Returns whether this file type is a block device.
- #[stable(feature = "file_type_ext", since = "1.5.0")]
- fn is_block_device(&self) -> bool;
- /// Returns whether this file type is a char device.
- #[stable(feature = "file_type_ext", since = "1.5.0")]
- fn is_char_device(&self) -> bool;
- /// Returns whether this file type is a fifo.
- #[stable(feature = "file_type_ext", since = "1.5.0")]
- fn is_fifo(&self) -> bool;
- /// Returns whether this file type is a socket.
- #[stable(feature = "file_type_ext", since = "1.5.0")]
- fn is_socket(&self) -> bool;
-}
-
-#[stable(feature = "file_type_ext", since = "1.5.0")]
-impl FileTypeExt for fs::FileType {
- fn is_block_device(&self) -> bool { false /*FIXME: Implement block device mode*/ }
- fn is_char_device(&self) -> bool { false /*FIXME: Implement char device mode*/ }
- fn is_fifo(&self) -> bool { false /*FIXME: Implement fifo mode*/ }
- fn is_socket(&self) -> bool { false /*FIXME: Implement socket mode*/ }
-}
-
-/// Creates a new symbolic link on the filesystem.
-///
-/// The `dst` path will be a symbolic link pointing to the `src` path.
-///
-/// # Note
-///
-/// On Windows, you must specify whether a symbolic link points to a file
-/// or directory. Use `os::windows::fs::symlink_file` to create a
-/// symbolic link to a file, or `os::windows::fs::symlink_dir` to create a
-/// symbolic link to a directory. Additionally, the process must have
-/// `SeCreateSymbolicLinkPrivilege` in order to be able to create a
-/// symbolic link.
-///
-/// # Examples
-///
-/// ```no_run
-/// use std::os::redox::fs;
-///
-/// fn main() -> std::io::Result<()> {
-/// fs::symlink("a.txt", "b.txt")?;
-/// Ok(())
-/// }
-/// ```
-#[stable(feature = "symlink", since = "1.1.0")]
-pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
-{
- sys::fs::symlink(src.as_ref(), dst.as_ref())
-}
-
-/// Redox-specific extensions to [`fs::DirBuilder`].
-///
-/// [`fs::DirBuilder`]: ../../../../std/fs/struct.DirBuilder.html
-#[stable(feature = "dir_builder", since = "1.6.0")]
-pub trait DirBuilderExt {
- /// Sets the mode to create new directories with. This option defaults to
- /// 0o777.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::fs::DirBuilder;
- /// use std::os::redox::fs::DirBuilderExt;
- ///
- /// let mut builder = DirBuilder::new();
- /// builder.mode(0o755);
- /// ```
- #[stable(feature = "dir_builder", since = "1.6.0")]
- fn mode(&mut self, mode: u32) -> &mut Self;
-}
-
-#[stable(feature = "dir_builder", since = "1.6.0")]
-impl DirBuilderExt for fs::DirBuilder {
- fn mode(&mut self, mode: u32) -> &mut fs::DirBuilder {
- self.as_inner_mut().set_mode(mode);
- self
- }
-}
diff --git a/ctr-std/src/sys/redox/ext/io.rs b/ctr-std/src/sys/redox/ext/io.rs
deleted file mode 100644
index c4d9956..0000000
--- a/ctr-std/src/sys/redox/ext/io.rs
+++ /dev/null
@@ -1,167 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Unix-specific extensions to general I/O primitives
-
-#![stable(feature = "rust1", since = "1.0.0")]
-
-use fs;
-use net;
-use sys;
-use io;
-use sys_common::{self, AsInner, FromInner, IntoInner};
-
-/// Raw file descriptors.
-#[stable(feature = "rust1", since = "1.0.0")]
-pub type RawFd = usize;
-
-/// A trait to extract the raw unix file descriptor from an underlying
-/// object.
-///
-/// This is only available on unix platforms and must be imported in order
-/// to call the method. Windows platforms have a corresponding `AsRawHandle`
-/// and `AsRawSocket` set of traits.
-#[stable(feature = "rust1", since = "1.0.0")]
-pub trait AsRawFd {
- /// Extracts the raw file descriptor.
- ///
- /// This method does **not** pass ownership of the raw file descriptor
- /// to the caller. The descriptor is only guaranteed to be valid while
- /// the original object has not yet been destroyed.
- #[stable(feature = "rust1", since = "1.0.0")]
- fn as_raw_fd(&self) -> RawFd;
-}
-
-/// A trait to express the ability to construct an object from a raw file
-/// descriptor.
-#[stable(feature = "from_raw_os", since = "1.1.0")]
-pub trait FromRawFd {
- /// Constructs a new instances of `Self` from the given raw file
- /// descriptor.
- ///
- /// This function **consumes ownership** of the specified file
- /// descriptor. The returned object will take responsibility for closing
- /// it when the object goes out of scope.
- ///
- /// This function is also unsafe as the primitives currently returned
- /// have the contract that they are the sole owner of the file
- /// descriptor they are wrapping. Usage of this function could
- /// accidentally allow violating this contract which can cause memory
- /// unsafety in code that relies on it being true.
- #[stable(feature = "from_raw_os", since = "1.1.0")]
- unsafe fn from_raw_fd(fd: RawFd) -> Self;
-}
-
-/// A trait to express the ability to consume an object and acquire ownership of
-/// its raw file descriptor.
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-pub trait IntoRawFd {
- /// Consumes this object, returning the raw underlying file descriptor.
- ///
- /// This function **transfers ownership** of the underlying file descriptor
- /// to the caller. Callers are then the unique owners of the file descriptor
- /// and must close the descriptor once it's no longer needed.
- #[stable(feature = "into_raw_os", since = "1.4.0")]
- fn into_raw_fd(self) -> RawFd;
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl AsRawFd for fs::File {
- fn as_raw_fd(&self) -> RawFd {
- self.as_inner().fd().raw()
- }
-}
-#[stable(feature = "from_raw_os", since = "1.1.0")]
-impl FromRawFd for fs::File {
- unsafe fn from_raw_fd(fd: RawFd) -> fs::File {
- fs::File::from_inner(sys::fs::File::from_inner(fd))
- }
-}
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-impl IntoRawFd for fs::File {
- fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_fd().into_raw()
- }
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl AsRawFd for net::TcpStream {
- fn as_raw_fd(&self) -> RawFd {
- self.as_inner().as_inner().fd().raw()
- }
-}
-#[stable(feature = "rust1", since = "1.0.0")]
-impl AsRawFd for net::TcpListener {
- fn as_raw_fd(&self) -> RawFd {
- self.as_inner().as_inner().fd().raw()
- }
-}
-#[stable(feature = "rust1", since = "1.0.0")]
-impl AsRawFd for net::UdpSocket {
- fn as_raw_fd(&self) -> RawFd {
- self.as_inner().as_inner().fd().raw()
- }
-}
-
-#[stable(feature = "asraw_stdio", since = "1.21.0")]
-impl AsRawFd for io::Stdin {
- fn as_raw_fd(&self) -> RawFd { 0 }
-}
-
-#[stable(feature = "asraw_stdio", since = "1.21.0")]
-impl AsRawFd for io::Stdout {
- fn as_raw_fd(&self) -> RawFd { 1 }
-}
-
-#[stable(feature = "asraw_stdio", since = "1.21.0")]
-impl AsRawFd for io::Stderr {
- fn as_raw_fd(&self) -> RawFd { 2 }
-}
-
-#[stable(feature = "from_raw_os", since = "1.1.0")]
-impl FromRawFd for net::TcpStream {
- unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
- let file = sys::fs::File::from_inner(fd);
- net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(file))
- }
-}
-#[stable(feature = "from_raw_os", since = "1.1.0")]
-impl FromRawFd for net::TcpListener {
- unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
- let file = sys::fs::File::from_inner(fd);
- net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(file))
- }
-}
-#[stable(feature = "from_raw_os", since = "1.1.0")]
-impl FromRawFd for net::UdpSocket {
- unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
- let file = sys::fs::File::from_inner(fd);
- net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(file))
- }
-}
-
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-impl IntoRawFd for net::TcpStream {
- fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_inner().into_fd().into_raw()
- }
-}
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-impl IntoRawFd for net::TcpListener {
- fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_inner().into_fd().into_raw()
- }
-}
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-impl IntoRawFd for net::UdpSocket {
- fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_inner().into_fd().into_raw()
- }
-}
diff --git a/ctr-std/src/sys/redox/ext/mod.rs b/ctr-std/src/sys/redox/ext/mod.rs
deleted file mode 100644
index cb2c75a..0000000
--- a/ctr-std/src/sys/redox/ext/mod.rs
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Experimental extensions to `std` for Unix platforms.
-//!
-//! For now, this module is limited to extracting file descriptors,
-//! but its functionality will grow over time.
-//!
-//! # Examples
-//!
-//! ```no_run
-//! use std::fs::File;
-//! use std::os::unix::prelude::*;
-//!
-//! fn main() {
-//! let f = File::create("foo.txt").unwrap();
-//! let fd = f.as_raw_fd();
-//!
-//! // use fd with native unix bindings
-//! }
-//! ```
-
-#![stable(feature = "rust1", since = "1.0.0")]
-#![doc(cfg(target_os = "redox"))]
-
-pub mod ffi;
-pub mod fs;
-pub mod io;
-pub mod net;
-pub mod process;
-pub mod thread;
-
-/// A prelude for conveniently writing platform-specific code.
-///
-/// Includes all extension traits, and some important type definitions.
-#[stable(feature = "rust1", since = "1.0.0")]
-pub mod prelude {
- #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
- pub use super::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd};
- #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
- pub use super::ffi::{OsStrExt, OsStringExt};
- #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
- pub use super::fs::{FileTypeExt, PermissionsExt, OpenOptionsExt, MetadataExt};
- #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
- pub use super::thread::JoinHandleExt;
- #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
- pub use super::process::{CommandExt, ExitStatusExt};
-}
diff --git a/ctr-std/src/sys/redox/ext/net.rs b/ctr-std/src/sys/redox/ext/net.rs
deleted file mode 100644
index 2ab7770..0000000
--- a/ctr-std/src/sys/redox/ext/net.rs
+++ /dev/null
@@ -1,769 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![stable(feature = "unix_socket_redox", since = "1.29")]
-
-//! Unix-specific networking functionality
-
-use fmt;
-use io::{self, Error, ErrorKind, Initializer};
-use net::Shutdown;
-use os::unix::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd};
-use path::Path;
-use time::Duration;
-use sys::{cvt, fd::FileDesc, syscall};
-
-/// An address associated with a Unix socket.
-///
-/// # Examples
-///
-/// ```
-/// use std::os::unix::net::UnixListener;
-///
-/// let socket = match UnixListener::bind("/tmp/sock") {
-/// Ok(sock) => sock,
-/// Err(e) => {
-/// println!("Couldn't bind: {:?}", e);
-/// return
-/// }
-/// };
-/// let addr = socket.local_addr().expect("Couldn't get local address");
-/// ```
-#[derive(Clone)]
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-pub struct SocketAddr(());
-
-impl SocketAddr {
- /// Returns the contents of this address if it is a `pathname` address.
- ///
- /// # Examples
- ///
- /// With a pathname:
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- /// use std::path::Path;
- ///
- /// let socket = UnixListener::bind("/tmp/sock").unwrap();
- /// let addr = socket.local_addr().expect("Couldn't get local address");
- /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock")));
- /// ```
- ///
- /// Without a pathname:
- ///
- /// ```
- /// use std::os::unix::net::UnixDatagram;
- ///
- /// let socket = UnixDatagram::unbound().unwrap();
- /// let addr = socket.local_addr().expect("Couldn't get local address");
- /// assert_eq!(addr.as_pathname(), None);
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn as_pathname(&self) -> Option<&Path> {
- None
- }
-
- /// Returns true if and only if the address is unnamed.
- ///
- /// # Examples
- ///
- /// A named address:
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- ///
- /// let socket = UnixListener::bind("/tmp/sock").unwrap();
- /// let addr = socket.local_addr().expect("Couldn't get local address");
- /// assert_eq!(addr.is_unnamed(), false);
- /// ```
- ///
- /// An unnamed address:
- ///
- /// ```
- /// use std::os::unix::net::UnixDatagram;
- ///
- /// let socket = UnixDatagram::unbound().unwrap();
- /// let addr = socket.local_addr().expect("Couldn't get local address");
- /// assert_eq!(addr.is_unnamed(), true);
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn is_unnamed(&self) -> bool {
- false
- }
-}
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl fmt::Debug for SocketAddr {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
- write!(fmt, "SocketAddr")
- }
-}
-
-/// A Unix stream socket.
-///
-/// # Examples
-///
-/// ```no_run
-/// use std::os::unix::net::UnixStream;
-/// use std::io::prelude::*;
-///
-/// let mut stream = UnixStream::connect("/path/to/my/socket").unwrap();
-/// stream.write_all(b"hello world").unwrap();
-/// let mut response = String::new();
-/// stream.read_to_string(&mut response).unwrap();
-/// println!("{}", response);
-/// ```
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-pub struct UnixStream(FileDesc);
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl fmt::Debug for UnixStream {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
- let mut builder = fmt.debug_struct("UnixStream");
- builder.field("fd", &self.0.raw());
- if let Ok(addr) = self.local_addr() {
- builder.field("local", &addr);
- }
- if let Ok(addr) = self.peer_addr() {
- builder.field("peer", &addr);
- }
- builder.finish()
- }
-}
-
-impl UnixStream {
- /// Connects to the socket named by `path`.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- ///
- /// let socket = match UnixStream::connect("/tmp/sock") {
- /// Ok(sock) => sock,
- /// Err(e) => {
- /// println!("Couldn't connect: {:?}", e);
- /// return
- /// }
- /// };
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
- if let Some(s) = path.as_ref().to_str() {
- cvt(syscall::open(format!("chan:{}", s), syscall::O_CLOEXEC))
- .map(FileDesc::new)
- .map(UnixStream)
- } else {
- Err(Error::new(
- ErrorKind::Other,
- "UnixStream::connect: non-utf8 paths not supported on redox"
- ))
- }
- }
-
- /// Creates an unnamed pair of connected sockets.
- ///
- /// Returns two `UnixStream`s which are connected to each other.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- ///
- /// let (sock1, sock2) = match UnixStream::pair() {
- /// Ok((sock1, sock2)) => (sock1, sock2),
- /// Err(e) => {
- /// println!("Couldn't create a pair of sockets: {:?}", e);
- /// return
- /// }
- /// };
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn pair() -> io::Result<(UnixStream, UnixStream)> {
- let server = cvt(syscall::open("chan:", syscall::O_CREAT | syscall::O_CLOEXEC))
- .map(FileDesc::new)?;
- let client = server.duplicate_path(b"connect")?;
- let stream = server.duplicate_path(b"listen")?;
- Ok((UnixStream(client), UnixStream(stream)))
- }
-
- /// Creates a new independently owned handle to the underlying socket.
- ///
- /// The returned `UnixStream` is a reference to the same stream that this
- /// object references. Both handles will read and write the same stream of
- /// data, and options set on one stream will be propagated to the other
- /// stream.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// let sock_copy = socket.try_clone().expect("Couldn't clone socket");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn try_clone(&self) -> io::Result<UnixStream> {
- self.0.duplicate().map(UnixStream)
- }
-
- /// Returns the socket address of the local half of this connection.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// let addr = socket.local_addr().expect("Couldn't get local address");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn local_addr(&self) -> io::Result<SocketAddr> {
- Err(Error::new(ErrorKind::Other, "UnixStream::local_addr unimplemented on redox"))
- }
-
- /// Returns the socket address of the remote half of this connection.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// let addr = socket.peer_addr().expect("Couldn't get peer address");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn peer_addr(&self) -> io::Result<SocketAddr> {
- Err(Error::new(ErrorKind::Other, "UnixStream::peer_addr unimplemented on redox"))
- }
-
- /// Sets the read timeout for the socket.
- ///
- /// If the provided value is [`None`], then [`read`] calls will block
- /// indefinitely. An [`Err`] is returned if the zero [`Duration`] is passed to this
- /// method.
- ///
- /// [`None`]: ../../../../std/option/enum.Option.html#variant.None
- /// [`Err`]: ../../../../std/result/enum.Result.html#variant.Err
- /// [`read`]: ../../../../std/io/trait.Read.html#tymethod.read
- /// [`Duration`]: ../../../../std/time/struct.Duration.html
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- /// use std::time::Duration;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
- /// ```
- ///
- /// An [`Err`] is returned if the zero [`Duration`] is passed to this
- /// method:
- ///
- /// ```no_run
- /// use std::io;
- /// use std::os::unix::net::UnixStream;
- /// use std::time::Duration;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
- /// let err = result.unwrap_err();
- /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn set_read_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
- Err(Error::new(ErrorKind::Other, "UnixStream::set_read_timeout unimplemented on redox"))
- }
-
- /// Sets the write timeout for the socket.
- ///
- /// If the provided value is [`None`], then [`write`] calls will block
- /// indefinitely. An [`Err`] is returned if the zero [`Duration`] is
- /// passed to this method.
- ///
- /// [`None`]: ../../../../std/option/enum.Option.html#variant.None
- /// [`Err`]: ../../../../std/result/enum.Result.html#variant.Err
- /// [`write`]: ../../../../std/io/trait.Write.html#tymethod.write
- /// [`Duration`]: ../../../../std/time/struct.Duration.html
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- /// use std::time::Duration;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout");
- /// ```
- ///
- /// An [`Err`] is returned if the zero [`Duration`] is passed to this
- /// method:
- ///
- /// ```no_run
- /// use std::io;
- /// use std::net::UdpSocket;
- /// use std::time::Duration;
- ///
- /// let socket = UdpSocket::bind("127.0.0.1:34254").unwrap();
- /// let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
- /// let err = result.unwrap_err();
- /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn set_write_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
- Err(Error::new(ErrorKind::Other, "UnixStream::set_write_timeout unimplemented on redox"))
- }
-
- /// Returns the read timeout of this socket.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- /// use std::time::Duration;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
- /// assert_eq!(socket.read_timeout().unwrap(), Some(Duration::new(1, 0)));
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
- Err(Error::new(ErrorKind::Other, "UnixStream::read_timeout unimplemented on redox"))
- }
-
- /// Returns the write timeout of this socket.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- /// use std::time::Duration;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout");
- /// assert_eq!(socket.write_timeout().unwrap(), Some(Duration::new(1, 0)));
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
- Err(Error::new(ErrorKind::Other, "UnixStream::write_timeout unimplemented on redox"))
- }
-
- /// Moves the socket into or out of nonblocking mode.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// socket.set_nonblocking(true).expect("Couldn't set nonblocking");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
- self.0.set_nonblocking(nonblocking)
- }
-
- /// Returns the value of the `SO_ERROR` option.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// if let Ok(Some(err)) = socket.take_error() {
- /// println!("Got error: {:?}", err);
- /// }
- /// ```
- ///
- /// # Platform specific
- /// On Redox this always returns None.
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn take_error(&self) -> io::Result<Option<io::Error>> {
- Ok(None)
- }
-
- /// Shuts down the read, write, or both halves of this connection.
- ///
- /// This function will cause all pending and future I/O calls on the
- /// specified portions to immediately return with an appropriate value
- /// (see the documentation of [`Shutdown`]).
- ///
- /// [`Shutdown`]: ../../../../std/net/enum.Shutdown.html
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixStream;
- /// use std::net::Shutdown;
- ///
- /// let socket = UnixStream::connect("/tmp/sock").unwrap();
- /// socket.shutdown(Shutdown::Both).expect("shutdown function failed");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> {
- Err(Error::new(ErrorKind::Other, "UnixStream::shutdown unimplemented on redox"))
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl io::Read for UnixStream {
- fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- io::Read::read(&mut &*self, buf)
- }
-
- #[inline]
- unsafe fn initializer(&self) -> Initializer {
- Initializer::nop()
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl<'a> io::Read for &'a UnixStream {
- fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- self.0.read(buf)
- }
-
- #[inline]
- unsafe fn initializer(&self) -> Initializer {
- Initializer::nop()
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl io::Write for UnixStream {
- fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
- io::Write::write(&mut &*self, buf)
- }
-
- fn flush(&mut self) -> io::Result<()> {
- io::Write::flush(&mut &*self)
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl<'a> io::Write for &'a UnixStream {
- fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
- self.0.write(buf)
- }
-
- fn flush(&mut self) -> io::Result<()> {
- Ok(())
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl AsRawFd for UnixStream {
- fn as_raw_fd(&self) -> RawFd {
- self.0.raw()
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl FromRawFd for UnixStream {
- unsafe fn from_raw_fd(fd: RawFd) -> UnixStream {
- UnixStream(FileDesc::new(fd))
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl IntoRawFd for UnixStream {
- fn into_raw_fd(self) -> RawFd {
- self.0.into_raw()
- }
-}
-
-/// A structure representing a Unix domain socket server.
-///
-/// # Examples
-///
-/// ```no_run
-/// use std::thread;
-/// use std::os::unix::net::{UnixStream, UnixListener};
-///
-/// fn handle_client(stream: UnixStream) {
-/// // ...
-/// }
-///
-/// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
-///
-/// // accept connections and process them, spawning a new thread for each one
-/// for stream in listener.incoming() {
-/// match stream {
-/// Ok(stream) => {
-/// /* connection succeeded */
-/// thread::spawn(|| handle_client(stream));
-/// }
-/// Err(err) => {
-/// /* connection failed */
-/// break;
-/// }
-/// }
-/// }
-/// ```
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-pub struct UnixListener(FileDesc);
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl fmt::Debug for UnixListener {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
- let mut builder = fmt.debug_struct("UnixListener");
- builder.field("fd", &self.0.raw());
- if let Ok(addr) = self.local_addr() {
- builder.field("local", &addr);
- }
- builder.finish()
- }
-}
-
-impl UnixListener {
- /// Creates a new `UnixListener` bound to the specified socket.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- ///
- /// let listener = match UnixListener::bind("/path/to/the/socket") {
- /// Ok(sock) => sock,
- /// Err(e) => {
- /// println!("Couldn't connect: {:?}", e);
- /// return
- /// }
- /// };
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
- if let Some(s) = path.as_ref().to_str() {
- cvt(syscall::open(format!("chan:{}", s), syscall::O_CREAT | syscall::O_CLOEXEC))
- .map(FileDesc::new)
- .map(UnixListener)
- } else {
- Err(Error::new(
- ErrorKind::Other,
- "UnixListener::bind: non-utf8 paths not supported on redox"
- ))
- }
- }
-
- /// Accepts a new incoming connection to this listener.
- ///
- /// This function will block the calling thread until a new Unix connection
- /// is established. When established, the corresponding [`UnixStream`] and
- /// the remote peer's address will be returned.
- ///
- /// [`UnixStream`]: ../../../../std/os/unix/net/struct.UnixStream.html
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- ///
- /// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
- ///
- /// match listener.accept() {
- /// Ok((socket, addr)) => println!("Got a client: {:?}", addr),
- /// Err(e) => println!("accept function failed: {:?}", e),
- /// }
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
- self.0.duplicate_path(b"listen").map(|fd| (UnixStream(fd), SocketAddr(())))
- }
-
- /// Creates a new independently owned handle to the underlying socket.
- ///
- /// The returned `UnixListener` is a reference to the same socket that this
- /// object references. Both handles can be used to accept incoming
- /// connections and options set on one listener will affect the other.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- ///
- /// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
- ///
- /// let listener_copy = listener.try_clone().expect("try_clone failed");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn try_clone(&self) -> io::Result<UnixListener> {
- self.0.duplicate().map(UnixListener)
- }
-
- /// Returns the local socket address of this listener.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- ///
- /// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
- ///
- /// let addr = listener.local_addr().expect("Couldn't get local address");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn local_addr(&self) -> io::Result<SocketAddr> {
- Err(Error::new(ErrorKind::Other, "UnixListener::local_addr unimplemented on redox"))
- }
-
- /// Moves the socket into or out of nonblocking mode.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- ///
- /// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
- ///
- /// listener.set_nonblocking(true).expect("Couldn't set non blocking");
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
- self.0.set_nonblocking(nonblocking)
- }
-
- /// Returns the value of the `SO_ERROR` option.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::os::unix::net::UnixListener;
- ///
- /// let listener = UnixListener::bind("/tmp/sock").unwrap();
- ///
- /// if let Ok(Some(err)) = listener.take_error() {
- /// println!("Got error: {:?}", err);
- /// }
- /// ```
- ///
- /// # Platform specific
- /// On Redox this always returns None.
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn take_error(&self) -> io::Result<Option<io::Error>> {
- Ok(None)
- }
-
- /// Returns an iterator over incoming connections.
- ///
- /// The iterator will never return [`None`] and will also not yield the
- /// peer's [`SocketAddr`] structure.
- ///
- /// [`None`]: ../../../../std/option/enum.Option.html#variant.None
- /// [`SocketAddr`]: struct.SocketAddr.html
- ///
- /// # Examples
- ///
- /// ```no_run
- /// use std::thread;
- /// use std::os::unix::net::{UnixStream, UnixListener};
- ///
- /// fn handle_client(stream: UnixStream) {
- /// // ...
- /// }
- ///
- /// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
- ///
- /// for stream in listener.incoming() {
- /// match stream {
- /// Ok(stream) => {
- /// thread::spawn(|| handle_client(stream));
- /// }
- /// Err(err) => {
- /// break;
- /// }
- /// }
- /// }
- /// ```
- #[stable(feature = "unix_socket_redox", since = "1.29")]
- pub fn incoming<'a>(&'a self) -> Incoming<'a> {
- Incoming { listener: self }
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl AsRawFd for UnixListener {
- fn as_raw_fd(&self) -> RawFd {
- self.0.raw()
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl FromRawFd for UnixListener {
- unsafe fn from_raw_fd(fd: RawFd) -> UnixListener {
- UnixListener(FileDesc::new(fd))
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl IntoRawFd for UnixListener {
- fn into_raw_fd(self) -> RawFd {
- self.0.into_raw()
- }
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl<'a> IntoIterator for &'a UnixListener {
- type Item = io::Result<UnixStream>;
- type IntoIter = Incoming<'a>;
-
- fn into_iter(self) -> Incoming<'a> {
- self.incoming()
- }
-}
-
-/// An iterator over incoming connections to a [`UnixListener`].
-///
-/// It will never return [`None`].
-///
-/// [`None`]: ../../../../std/option/enum.Option.html#variant.None
-/// [`UnixListener`]: struct.UnixListener.html
-///
-/// # Examples
-///
-/// ```no_run
-/// use std::thread;
-/// use std::os::unix::net::{UnixStream, UnixListener};
-///
-/// fn handle_client(stream: UnixStream) {
-/// // ...
-/// }
-///
-/// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
-///
-/// for stream in listener.incoming() {
-/// match stream {
-/// Ok(stream) => {
-/// thread::spawn(|| handle_client(stream));
-/// }
-/// Err(err) => {
-/// break;
-/// }
-/// }
-/// }
-/// ```
-#[derive(Debug)]
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-pub struct Incoming<'a> {
- listener: &'a UnixListener,
-}
-
-#[stable(feature = "unix_socket_redox", since = "1.29")]
-impl<'a> Iterator for Incoming<'a> {
- type Item = io::Result<UnixStream>;
-
- fn next(&mut self) -> Option<io::Result<UnixStream>> {
- Some(self.listener.accept().map(|s| s.0))
- }
-
- fn size_hint(&self) -> (usize, Option<usize>) {
- (usize::max_value(), None)
- }
-}
diff --git a/ctr-std/src/sys/redox/ext/process.rs b/ctr-std/src/sys/redox/ext/process.rs
deleted file mode 100644
index cfb6d5f..0000000
--- a/ctr-std/src/sys/redox/ext/process.rs
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Redox-specific extensions to primitives in the `std::process` module.
-
-#![stable(feature = "rust1", since = "1.0.0")]
-
-use io;
-use os::unix::io::{FromRawFd, RawFd, AsRawFd, IntoRawFd};
-use process;
-use sys;
-use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner};
-
-/// Redox-specific extensions to the [`process::Command`] builder,
-///
-/// [`process::Command`]: ../../../../std/process/struct.Command.html
-#[stable(feature = "rust1", since = "1.0.0")]
-pub trait CommandExt {
- /// Sets the child process's user id. This translates to a
- /// `setuid` call in the child process. Failure in the `setuid`
- /// call will cause the spawn to fail.
- #[stable(feature = "rust1", since = "1.0.0")]
- fn uid(&mut self, id: u32) -> &mut process::Command;
-
- /// Similar to `uid`, but sets the group id of the child process. This has
- /// the same semantics as the `uid` field.
- #[stable(feature = "rust1", since = "1.0.0")]
- fn gid(&mut self, id: u32) -> &mut process::Command;
-
- /// Schedules a closure to be run just before the `exec` function is
- /// invoked.
- ///
- /// The closure is allowed to return an I/O error whose OS error code will
- /// be communicated back to the parent and returned as an error from when
- /// the spawn was requested.
- ///
- /// Multiple closures can be registered and they will be called in order of
- /// their registration. If a closure returns `Err` then no further closures
- /// will be called and the spawn operation will immediately return with a
- /// failure.
- ///
- /// # Notes
- ///
- /// This closure will be run in the context of the child process after a
- /// `fork`. This primarily means that any modifications made to memory on
- /// behalf of this closure will **not** be visible to the parent process.
- /// This is often a very constrained environment where normal operations
- /// like `malloc` or acquiring a mutex are not guaranteed to work (due to
- /// other threads perhaps still running when the `fork` was run).
- ///
- /// When this closure is run, aspects such as the stdio file descriptors and
- /// working directory have successfully been changed, so output to these
- /// locations may not appear where intended.
- #[stable(feature = "process_exec", since = "1.15.0")]
- fn before_exec<F>(&mut self, f: F) -> &mut process::Command
- where F: FnMut() -> io::Result<()> + Send + Sync + 'static;
-
- /// Performs all the required setup by this `Command`, followed by calling
- /// the `execvp` syscall.
- ///
- /// On success this function will not return, and otherwise it will return
- /// an error indicating why the exec (or another part of the setup of the
- /// `Command`) failed.
- ///
- /// This function, unlike `spawn`, will **not** `fork` the process to create
- /// a new child. Like spawn, however, the default behavior for the stdio
- /// descriptors will be to inherited from the current process.
- ///
- /// # Notes
- ///
- /// The process may be in a "broken state" if this function returns in
- /// error. For example the working directory, environment variables, signal
- /// handling settings, various user/group information, or aspects of stdio
- /// file descriptors may have changed. If a "transactional spawn" is
- /// required to gracefully handle errors it is recommended to use the
- /// cross-platform `spawn` instead.
- #[stable(feature = "process_exec2", since = "1.9.0")]
- fn exec(&mut self) -> io::Error;
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl CommandExt for process::Command {
- fn uid(&mut self, id: u32) -> &mut process::Command {
- self.as_inner_mut().uid(id);
- self
- }
-
- fn gid(&mut self, id: u32) -> &mut process::Command {
- self.as_inner_mut().gid(id);
- self
- }
-
- fn before_exec<F>(&mut self, f: F) -> &mut process::Command
- where F: FnMut() -> io::Result<()> + Send + Sync + 'static
- {
- self.as_inner_mut().before_exec(Box::new(f));
- self
- }
-
- fn exec(&mut self) -> io::Error {
- self.as_inner_mut().exec(sys::process::Stdio::Inherit)
- }
-}
-
-/// Redox-specific extensions to [`process::ExitStatus`].
-///
-/// [`process::ExitStatus`]: ../../../../std/process/struct.ExitStatus.html
-#[stable(feature = "rust1", since = "1.0.0")]
-pub trait ExitStatusExt {
- /// Creates a new `ExitStatus` from the raw underlying `i32` return value of
- /// a process.
- #[stable(feature = "exit_status_from", since = "1.12.0")]
- fn from_raw(raw: i32) -> Self;
-
- /// If the process was terminated by a signal, returns that signal.
- #[stable(feature = "rust1", since = "1.0.0")]
- fn signal(&self) -> Option<i32>;
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl ExitStatusExt for process::ExitStatus {
- fn from_raw(raw: i32) -> Self {
- process::ExitStatus::from_inner(From::from(raw))
- }
-
- fn signal(&self) -> Option<i32> {
- self.as_inner().signal()
- }
-}
-
-#[stable(feature = "process_extensions", since = "1.2.0")]
-impl FromRawFd for process::Stdio {
- unsafe fn from_raw_fd(fd: RawFd) -> process::Stdio {
- let fd = sys::fd::FileDesc::new(fd);
- let io = sys::process::Stdio::Fd(fd);
- process::Stdio::from_inner(io)
- }
-}
-
-#[stable(feature = "process_extensions", since = "1.2.0")]
-impl AsRawFd for process::ChildStdin {
- fn as_raw_fd(&self) -> RawFd {
- self.as_inner().fd().raw()
- }
-}
-
-#[stable(feature = "process_extensions", since = "1.2.0")]
-impl AsRawFd for process::ChildStdout {
- fn as_raw_fd(&self) -> RawFd {
- self.as_inner().fd().raw()
- }
-}
-
-#[stable(feature = "process_extensions", since = "1.2.0")]
-impl AsRawFd for process::ChildStderr {
- fn as_raw_fd(&self) -> RawFd {
- self.as_inner().fd().raw()
- }
-}
-
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-impl IntoRawFd for process::ChildStdin {
- fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_fd().into_raw()
- }
-}
-
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-impl IntoRawFd for process::ChildStdout {
- fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_fd().into_raw()
- }
-}
-
-#[stable(feature = "into_raw_os", since = "1.4.0")]
-impl IntoRawFd for process::ChildStderr {
- fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_fd().into_raw()
- }
-}
diff --git a/ctr-std/src/sys/redox/ext/thread.rs b/ctr-std/src/sys/redox/ext/thread.rs
deleted file mode 100644
index 71ff0d4..0000000
--- a/ctr-std/src/sys/redox/ext/thread.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Redox-specific extensions to primitives in the `std::thread` module.
-
-#![stable(feature = "thread_extensions", since = "1.9.0")]
-
-use sys_common::{AsInner, IntoInner};
-use thread::JoinHandle;
-
-#[stable(feature = "thread_extensions", since = "1.9.0")]
-#[allow(deprecated)]
-pub type RawPthread = usize;
-
-/// Redox-specific extensions to [`thread::JoinHandle`].
-///
-/// [`thread::JoinHandle`]: ../../../../std/thread/struct.JoinHandle.html
-#[stable(feature = "thread_extensions", since = "1.9.0")]
-pub trait JoinHandleExt {
- /// Extracts the raw pthread_t without taking ownership
- #[stable(feature = "thread_extensions", since = "1.9.0")]
- fn as_pthread_t(&self) -> RawPthread;
-
- /// Consumes the thread, returning the raw pthread_t
- ///
- /// This function **transfers ownership** of the underlying pthread_t to
- /// the caller. Callers are then the unique owners of the pthread_t and
- /// must either detach or join the pthread_t once it's no longer needed.
- #[stable(feature = "thread_extensions", since = "1.9.0")]
- fn into_pthread_t(self) -> RawPthread;
-}
-
-#[stable(feature = "thread_extensions", since = "1.9.0")]
-impl<T> JoinHandleExt for JoinHandle<T> {
- fn as_pthread_t(&self) -> RawPthread {
- self.as_inner().id() as RawPthread
- }
-
- fn into_pthread_t(self) -> RawPthread {
- self.into_inner().into_id() as RawPthread
- }
-}