Custom feature gate (I think?)

This commit is contained in:
jD91mZM2
2018-06-14 18:21:21 +02:00
parent 419500710d
commit c5977e3ea7

View File

@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![stable(feature = "unix_socket", since = "1.10.0")] #![stable(feature = "unix_socket_redox", since = "1.27.0")]
//! Unix-specific networking functionality //! Unix-specific networking functionality
@@ -36,7 +36,7 @@ use sys::{cvt, fd::FileDesc, syscall};
/// }; /// };
/// let addr = socket.local_addr().expect("Couldn't get local address"); /// let addr = socket.local_addr().expect("Couldn't get local address");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
#[derive(Clone)] #[derive(Clone)]
pub struct SocketAddr; pub struct SocketAddr;
@@ -65,12 +65,12 @@ impl SocketAddr {
/// let addr = socket.local_addr().expect("Couldn't get local address"); /// let addr = socket.local_addr().expect("Couldn't get local address");
/// assert_eq!(addr.as_pathname(), None); /// assert_eq!(addr.as_pathname(), None);
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn as_pathname(&self) -> Option<&Path> { pub fn as_pathname(&self) -> Option<&Path> {
None None
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl fmt::Debug for SocketAddr { impl fmt::Debug for SocketAddr {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "SocketAddr") write!(fmt, "SocketAddr")
@@ -91,10 +91,10 @@ impl fmt::Debug for SocketAddr {
/// stream.read_to_string(&mut response).unwrap(); /// stream.read_to_string(&mut response).unwrap();
/// println!("{}", response); /// println!("{}", response);
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub struct UnixStream(FileDesc); pub struct UnixStream(FileDesc);
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl fmt::Debug for UnixStream { impl fmt::Debug for UnixStream {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut builder = fmt.debug_struct("UnixStream"); let mut builder = fmt.debug_struct("UnixStream");
@@ -125,7 +125,7 @@ impl UnixStream {
/// } /// }
/// }; /// };
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> { pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
if let Some(s) = path.as_ref().to_str() { if let Some(s) = path.as_ref().to_str() {
cvt(syscall::open(format!("chan:{}", s), syscall::O_CLOEXEC)) cvt(syscall::open(format!("chan:{}", s), syscall::O_CLOEXEC))
@@ -156,7 +156,7 @@ impl UnixStream {
/// } /// }
/// }; /// };
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn pair() -> io::Result<(UnixStream, UnixStream)> { pub fn pair() -> io::Result<(UnixStream, UnixStream)> {
let server = cvt(syscall::open("chan:", syscall::O_CREAT | syscall::O_CLOEXEC)) let server = cvt(syscall::open("chan:", syscall::O_CREAT | syscall::O_CLOEXEC))
.map(FileDesc::new)?; .map(FileDesc::new)?;
@@ -180,7 +180,7 @@ impl UnixStream {
/// let socket = UnixStream::connect("/tmp/sock").unwrap(); /// let socket = UnixStream::connect("/tmp/sock").unwrap();
/// let sock_copy = socket.try_clone().expect("Couldn't clone socket"); /// let sock_copy = socket.try_clone().expect("Couldn't clone socket");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn try_clone(&self) -> io::Result<UnixStream> { pub fn try_clone(&self) -> io::Result<UnixStream> {
self.0.duplicate().map(UnixStream) self.0.duplicate().map(UnixStream)
} }
@@ -195,7 +195,7 @@ impl UnixStream {
/// let socket = UnixStream::connect("/tmp/sock").unwrap(); /// let socket = UnixStream::connect("/tmp/sock").unwrap();
/// let addr = socket.local_addr().expect("Couldn't get local address"); /// let addr = socket.local_addr().expect("Couldn't get local address");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn local_addr(&self) -> io::Result<SocketAddr> { pub fn local_addr(&self) -> io::Result<SocketAddr> {
Err(Error::new(ErrorKind::Other, "UnixStream::local_addr unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixStream::local_addr unimplemented on redox"))
} }
@@ -210,7 +210,7 @@ impl UnixStream {
/// let socket = UnixStream::connect("/tmp/sock").unwrap(); /// let socket = UnixStream::connect("/tmp/sock").unwrap();
/// let addr = socket.peer_addr().expect("Couldn't get peer address"); /// let addr = socket.peer_addr().expect("Couldn't get peer address");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn peer_addr(&self) -> io::Result<SocketAddr> { pub fn peer_addr(&self) -> io::Result<SocketAddr> {
Err(Error::new(ErrorKind::Other, "UnixStream::peer_addr unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixStream::peer_addr unimplemented on redox"))
} }
@@ -249,7 +249,7 @@ impl UnixStream {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn set_read_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> { pub fn set_read_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
Err(Error::new(ErrorKind::Other, "UnixStream::set_read_timeout unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixStream::set_read_timeout unimplemented on redox"))
} }
@@ -288,7 +288,7 @@ impl UnixStream {
/// let err = result.unwrap_err(); /// let err = result.unwrap_err();
/// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn set_write_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> { pub fn set_write_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
Err(Error::new(ErrorKind::Other, "UnixStream::set_write_timeout unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixStream::set_write_timeout unimplemented on redox"))
} }
@@ -305,7 +305,7 @@ impl UnixStream {
/// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); /// 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))); /// assert_eq!(socket.read_timeout().unwrap(), Some(Duration::new(1, 0)));
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn read_timeout(&self) -> io::Result<Option<Duration>> { pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
Err(Error::new(ErrorKind::Other, "UnixStream::read_timeout unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixStream::read_timeout unimplemented on redox"))
} }
@@ -322,7 +322,7 @@ impl UnixStream {
/// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout"); /// 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))); /// assert_eq!(socket.write_timeout().unwrap(), Some(Duration::new(1, 0)));
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn write_timeout(&self) -> io::Result<Option<Duration>> { pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
Err(Error::new(ErrorKind::Other, "UnixStream::write_timeout unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixStream::write_timeout unimplemented on redox"))
} }
@@ -337,7 +337,7 @@ impl UnixStream {
/// let socket = UnixStream::connect("/tmp/sock").unwrap(); /// let socket = UnixStream::connect("/tmp/sock").unwrap();
/// socket.set_nonblocking(true).expect("Couldn't set nonblocking"); /// socket.set_nonblocking(true).expect("Couldn't set nonblocking");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
self.0.set_nonblocking(nonblocking) self.0.set_nonblocking(nonblocking)
} }
@@ -354,7 +354,7 @@ impl UnixStream {
/// println!("Got error: {:?}", err); /// println!("Got error: {:?}", err);
/// } /// }
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn take_error(&self) -> io::Result<Option<io::Error>> { pub fn take_error(&self) -> io::Result<Option<io::Error>> {
Ok(None) Ok(None)
} }
@@ -376,13 +376,13 @@ impl UnixStream {
/// let socket = UnixStream::connect("/tmp/sock").unwrap(); /// let socket = UnixStream::connect("/tmp/sock").unwrap();
/// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); /// socket.shutdown(Shutdown::Both).expect("shutdown function failed");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> { pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> {
Err(Error::new(ErrorKind::Other, "UnixStream::shutdown unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixStream::shutdown unimplemented on redox"))
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl io::Read for UnixStream { impl io::Read for UnixStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
io::Read::read(&mut &*self, buf) io::Read::read(&mut &*self, buf)
@@ -394,7 +394,7 @@ impl io::Read for UnixStream {
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl<'a> io::Read for &'a UnixStream { impl<'a> io::Read for &'a UnixStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf) self.0.read(buf)
@@ -406,7 +406,7 @@ impl<'a> io::Read for &'a UnixStream {
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl io::Write for UnixStream { impl io::Write for UnixStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
io::Write::write(&mut &*self, buf) io::Write::write(&mut &*self, buf)
@@ -417,7 +417,7 @@ impl io::Write for UnixStream {
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl<'a> io::Write for &'a UnixStream { impl<'a> io::Write for &'a UnixStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf) self.0.write(buf)
@@ -428,21 +428,21 @@ impl<'a> io::Write for &'a UnixStream {
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl AsRawFd for UnixStream { impl AsRawFd for UnixStream {
fn as_raw_fd(&self) -> RawFd { fn as_raw_fd(&self) -> RawFd {
self.0.raw() self.0.raw()
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl FromRawFd for UnixStream { impl FromRawFd for UnixStream {
unsafe fn from_raw_fd(fd: RawFd) -> UnixStream { unsafe fn from_raw_fd(fd: RawFd) -> UnixStream {
UnixStream(FileDesc::new(fd)) UnixStream(FileDesc::new(fd))
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl IntoRawFd for UnixStream { impl IntoRawFd for UnixStream {
fn into_raw_fd(self) -> RawFd { fn into_raw_fd(self) -> RawFd {
self.0.into_raw() self.0.into_raw()
@@ -477,10 +477,10 @@ impl IntoRawFd for UnixStream {
/// } /// }
/// } /// }
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub struct UnixListener(FileDesc); pub struct UnixListener(FileDesc);
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl fmt::Debug for UnixListener { impl fmt::Debug for UnixListener {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut builder = fmt.debug_struct("UnixListener"); let mut builder = fmt.debug_struct("UnixListener");
@@ -508,7 +508,7 @@ impl UnixListener {
/// } /// }
/// }; /// };
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> { pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
if let Some(s) = path.as_ref().to_str() { if let Some(s) = path.as_ref().to_str() {
cvt(syscall::open(format!("chan:{}", s), syscall::O_CREAT | syscall::O_CLOEXEC)) cvt(syscall::open(format!("chan:{}", s), syscall::O_CREAT | syscall::O_CLOEXEC))
@@ -542,7 +542,7 @@ impl UnixListener {
/// Err(e) => println!("accept function failed: {:?}", e), /// Err(e) => println!("accept function failed: {:?}", e),
/// } /// }
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> { pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
self.0.duplicate_path(b"listen").map(|fd| (UnixStream(fd), SocketAddr)) self.0.duplicate_path(b"listen").map(|fd| (UnixStream(fd), SocketAddr))
} }
@@ -562,7 +562,7 @@ impl UnixListener {
/// ///
/// let listener_copy = listener.try_clone().expect("try_clone failed"); /// let listener_copy = listener.try_clone().expect("try_clone failed");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn try_clone(&self) -> io::Result<UnixListener> { pub fn try_clone(&self) -> io::Result<UnixListener> {
self.0.duplicate().map(UnixListener) self.0.duplicate().map(UnixListener)
} }
@@ -578,7 +578,7 @@ impl UnixListener {
/// ///
/// let addr = listener.local_addr().expect("Couldn't get local address"); /// let addr = listener.local_addr().expect("Couldn't get local address");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn local_addr(&self) -> io::Result<SocketAddr> { pub fn local_addr(&self) -> io::Result<SocketAddr> {
Err(Error::new(ErrorKind::Other, "UnixListener::local_addr unimplemented on redox")) Err(Error::new(ErrorKind::Other, "UnixListener::local_addr unimplemented on redox"))
} }
@@ -594,7 +594,7 @@ impl UnixListener {
/// ///
/// listener.set_nonblocking(true).expect("Couldn't set non blocking"); /// listener.set_nonblocking(true).expect("Couldn't set non blocking");
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
self.0.set_nonblocking(nonblocking) self.0.set_nonblocking(nonblocking)
} }
@@ -612,7 +612,7 @@ impl UnixListener {
/// println!("Got error: {:?}", err); /// println!("Got error: {:?}", err);
/// } /// }
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn take_error(&self) -> io::Result<Option<io::Error>> { pub fn take_error(&self) -> io::Result<Option<io::Error>> {
Ok(None) Ok(None)
} }
@@ -648,34 +648,34 @@ impl UnixListener {
/// } /// }
/// } /// }
/// ``` /// ```
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub fn incoming<'a>(&'a self) -> Incoming<'a> { pub fn incoming<'a>(&'a self) -> Incoming<'a> {
Incoming { listener: self } Incoming { listener: self }
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl AsRawFd for UnixListener { impl AsRawFd for UnixListener {
fn as_raw_fd(&self) -> RawFd { fn as_raw_fd(&self) -> RawFd {
self.0.raw() self.0.raw()
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl FromRawFd for UnixListener { impl FromRawFd for UnixListener {
unsafe fn from_raw_fd(fd: RawFd) -> UnixListener { unsafe fn from_raw_fd(fd: RawFd) -> UnixListener {
UnixListener(FileDesc::new(fd)) UnixListener(FileDesc::new(fd))
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl IntoRawFd for UnixListener { impl IntoRawFd for UnixListener {
fn into_raw_fd(self) -> RawFd { fn into_raw_fd(self) -> RawFd {
self.0.into_raw() self.0.into_raw()
} }
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl<'a> IntoIterator for &'a UnixListener { impl<'a> IntoIterator for &'a UnixListener {
type Item = io::Result<UnixStream>; type Item = io::Result<UnixStream>;
type IntoIter = Incoming<'a>; type IntoIter = Incoming<'a>;
@@ -716,12 +716,12 @@ impl<'a> IntoIterator for &'a UnixListener {
/// } /// }
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
pub struct Incoming<'a> { pub struct Incoming<'a> {
listener: &'a UnixListener, listener: &'a UnixListener,
} }
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket_redox", since = "1.27.0")]
impl<'a> Iterator for Incoming<'a> { impl<'a> Iterator for Incoming<'a> {
type Item = io::Result<UnixStream>; type Item = io::Result<UnixStream>;