Skip to content

Commit 1581971

Browse files
committedJul 24, 2018
Stablize Redox Unix Sockets
1 parent 0b56e7f commit 1581971

File tree

1 file changed

+41
-1
lines changed
  • src/libstd/sys/redox/ext

1 file changed

+41
-1
lines changed
 

‎src/libstd/sys/redox/ext/net.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![unstable(feature = "unix_socket_redox", reason = "new feature", issue="51553")]
11+
#![stable(feature = "unix_socket_redox", since = "1.29")]
1212

1313
//! Unix-specific networking functionality
1414
@@ -37,6 +37,7 @@ use sys::{cvt, fd::FileDesc, syscall};
3737
/// let addr = socket.local_addr().expect("Couldn't get local address");
3838
/// ```
3939
#[derive(Clone)]
40+
#[stable(feature = "unix_socket_redox", since = "1.29")]
4041
pub struct SocketAddr(());
4142

4243
impl SocketAddr {
@@ -64,6 +65,7 @@ impl SocketAddr {
6465
/// let addr = socket.local_addr().expect("Couldn't get local address");
6566
/// assert_eq!(addr.as_pathname(), None);
6667
/// ```
68+
#[stable(feature = "unix_socket_redox", since = "1.29")]
6769
pub fn as_pathname(&self) -> Option<&Path> {
6870
None
6971
}
@@ -91,10 +93,12 @@ impl SocketAddr {
9193
/// let addr = socket.local_addr().expect("Couldn't get local address");
9294
/// assert_eq!(addr.is_unnamed(), true);
9395
/// ```
96+
#[stable(feature = "unix_socket_redox", since = "1.29")]
9497
pub fn is_unnamed(&self) -> bool {
9598
false
9699
}
97100
}
101+
#[stable(feature = "unix_socket_redox", since = "1.29")]
98102
impl fmt::Debug for SocketAddr {
99103
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
100104
write!(fmt, "SocketAddr")
@@ -115,8 +119,10 @@ impl fmt::Debug for SocketAddr {
115119
/// stream.read_to_string(&mut response).unwrap();
116120
/// println!("{}", response);
117121
/// ```
122+
#[stable(feature = "unix_socket_redox", since = "1.29")]
118123
pub struct UnixStream(FileDesc);
119124

125+
#[stable(feature = "unix_socket_redox", since = "1.29")]
120126
impl fmt::Debug for UnixStream {
121127
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
122128
let mut builder = fmt.debug_struct("UnixStream");
@@ -147,6 +153,7 @@ impl UnixStream {
147153
/// }
148154
/// };
149155
/// ```
156+
#[stable(feature = "unix_socket_redox", since = "1.29")]
150157
pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
151158
if let Some(s) = path.as_ref().to_str() {
152159
cvt(syscall::open(format!("chan:{}", s), syscall::O_CLOEXEC))
@@ -177,6 +184,7 @@ impl UnixStream {
177184
/// }
178185
/// };
179186
/// ```
187+
#[stable(feature = "unix_socket_redox", since = "1.29")]
180188
pub fn pair() -> io::Result<(UnixStream, UnixStream)> {
181189
let server = cvt(syscall::open("chan:", syscall::O_CREAT | syscall::O_CLOEXEC))
182190
.map(FileDesc::new)?;
@@ -200,6 +208,7 @@ impl UnixStream {
200208
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
201209
/// let sock_copy = socket.try_clone().expect("Couldn't clone socket");
202210
/// ```
211+
#[stable(feature = "unix_socket_redox", since = "1.29")]
203212
pub fn try_clone(&self) -> io::Result<UnixStream> {
204213
self.0.duplicate().map(UnixStream)
205214
}
@@ -214,6 +223,7 @@ impl UnixStream {
214223
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
215224
/// let addr = socket.local_addr().expect("Couldn't get local address");
216225
/// ```
226+
#[stable(feature = "unix_socket_redox", since = "1.29")]
217227
pub fn local_addr(&self) -> io::Result<SocketAddr> {
218228
Err(Error::new(ErrorKind::Other, "UnixStream::local_addr unimplemented on redox"))
219229
}
@@ -228,6 +238,7 @@ impl UnixStream {
228238
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
229239
/// let addr = socket.peer_addr().expect("Couldn't get peer address");
230240
/// ```
241+
#[stable(feature = "unix_socket_redox", since = "1.29")]
231242
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
232243
Err(Error::new(ErrorKind::Other, "UnixStream::peer_addr unimplemented on redox"))
233244
}
@@ -266,6 +277,7 @@ impl UnixStream {
266277
/// let err = result.unwrap_err();
267278
/// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
268279
/// ```
280+
#[stable(feature = "unix_socket_redox", since = "1.29")]
269281
pub fn set_read_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
270282
Err(Error::new(ErrorKind::Other, "UnixStream::set_read_timeout unimplemented on redox"))
271283
}
@@ -304,6 +316,7 @@ impl UnixStream {
304316
/// let err = result.unwrap_err();
305317
/// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
306318
/// ```
319+
#[stable(feature = "unix_socket_redox", since = "1.29")]
307320
pub fn set_write_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
308321
Err(Error::new(ErrorKind::Other, "UnixStream::set_write_timeout unimplemented on redox"))
309322
}
@@ -320,6 +333,7 @@ impl UnixStream {
320333
/// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
321334
/// assert_eq!(socket.read_timeout().unwrap(), Some(Duration::new(1, 0)));
322335
/// ```
336+
#[stable(feature = "unix_socket_redox", since = "1.29")]
323337
pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
324338
Err(Error::new(ErrorKind::Other, "UnixStream::read_timeout unimplemented on redox"))
325339
}
@@ -336,6 +350,7 @@ impl UnixStream {
336350
/// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout");
337351
/// assert_eq!(socket.write_timeout().unwrap(), Some(Duration::new(1, 0)));
338352
/// ```
353+
#[stable(feature = "unix_socket_redox", since = "1.29")]
339354
pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
340355
Err(Error::new(ErrorKind::Other, "UnixStream::write_timeout unimplemented on redox"))
341356
}
@@ -350,6 +365,7 @@ impl UnixStream {
350365
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
351366
/// socket.set_nonblocking(true).expect("Couldn't set nonblocking");
352367
/// ```
368+
#[stable(feature = "unix_socket_redox", since = "1.29")]
353369
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
354370
self.0.set_nonblocking(nonblocking)
355371
}
@@ -369,6 +385,7 @@ impl UnixStream {
369385
///
370386
/// # Platform specific
371387
/// On Redox this always returns None.
388+
#[stable(feature = "unix_socket_redox", since = "1.29")]
372389
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
373390
Ok(None)
374391
}
@@ -390,11 +407,13 @@ impl UnixStream {
390407
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
391408
/// socket.shutdown(Shutdown::Both).expect("shutdown function failed");
392409
/// ```
410+
#[stable(feature = "unix_socket_redox", since = "1.29")]
393411
pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> {
394412
Err(Error::new(ErrorKind::Other, "UnixStream::shutdown unimplemented on redox"))
395413
}
396414
}
397415

416+
#[stable(feature = "unix_socket_redox", since = "1.29")]
398417
impl io::Read for UnixStream {
399418
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
400419
io::Read::read(&mut &*self, buf)
@@ -406,6 +425,7 @@ impl io::Read for UnixStream {
406425
}
407426
}
408427

428+
#[stable(feature = "unix_socket_redox", since = "1.29")]
409429
impl<'a> io::Read for &'a UnixStream {
410430
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
411431
self.0.read(buf)
@@ -417,6 +437,7 @@ impl<'a> io::Read for &'a UnixStream {
417437
}
418438
}
419439

440+
#[stable(feature = "unix_socket_redox", since = "1.29")]
420441
impl io::Write for UnixStream {
421442
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
422443
io::Write::write(&mut &*self, buf)
@@ -427,6 +448,7 @@ impl io::Write for UnixStream {
427448
}
428449
}
429450

451+
#[stable(feature = "unix_socket_redox", since = "1.29")]
430452
impl<'a> io::Write for &'a UnixStream {
431453
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
432454
self.0.write(buf)
@@ -437,18 +459,21 @@ impl<'a> io::Write for &'a UnixStream {
437459
}
438460
}
439461

462+
#[stable(feature = "unix_socket_redox", since = "1.29")]
440463
impl AsRawFd for UnixStream {
441464
fn as_raw_fd(&self) -> RawFd {
442465
self.0.raw()
443466
}
444467
}
445468

469+
#[stable(feature = "unix_socket_redox", since = "1.29")]
446470
impl FromRawFd for UnixStream {
447471
unsafe fn from_raw_fd(fd: RawFd) -> UnixStream {
448472
UnixStream(FileDesc::new(fd))
449473
}
450474
}
451475

476+
#[stable(feature = "unix_socket_redox", since = "1.29")]
452477
impl IntoRawFd for UnixStream {
453478
fn into_raw_fd(self) -> RawFd {
454479
self.0.into_raw()
@@ -483,8 +508,10 @@ impl IntoRawFd for UnixStream {
483508
/// }
484509
/// }
485510
/// ```
511+
#[stable(feature = "unix_socket_redox", since = "1.29")]
486512
pub struct UnixListener(FileDesc);
487513

514+
#[stable(feature = "unix_socket_redox", since = "1.29")]
488515
impl fmt::Debug for UnixListener {
489516
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
490517
let mut builder = fmt.debug_struct("UnixListener");
@@ -512,6 +539,7 @@ impl UnixListener {
512539
/// }
513540
/// };
514541
/// ```
542+
#[stable(feature = "unix_socket_redox", since = "1.29")]
515543
pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
516544
if let Some(s) = path.as_ref().to_str() {
517545
cvt(syscall::open(format!("chan:{}", s), syscall::O_CREAT | syscall::O_CLOEXEC))
@@ -545,6 +573,7 @@ impl UnixListener {
545573
/// Err(e) => println!("accept function failed: {:?}", e),
546574
/// }
547575
/// ```
576+
#[stable(feature = "unix_socket_redox", since = "1.29")]
548577
pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
549578
self.0.duplicate_path(b"listen").map(|fd| (UnixStream(fd), SocketAddr(())))
550579
}
@@ -564,6 +593,7 @@ impl UnixListener {
564593
///
565594
/// let listener_copy = listener.try_clone().expect("try_clone failed");
566595
/// ```
596+
#[stable(feature = "unix_socket_redox", since = "1.29")]
567597
pub fn try_clone(&self) -> io::Result<UnixListener> {
568598
self.0.duplicate().map(UnixListener)
569599
}
@@ -579,6 +609,7 @@ impl UnixListener {
579609
///
580610
/// let addr = listener.local_addr().expect("Couldn't get local address");
581611
/// ```
612+
#[stable(feature = "unix_socket_redox", since = "1.29")]
582613
pub fn local_addr(&self) -> io::Result<SocketAddr> {
583614
Err(Error::new(ErrorKind::Other, "UnixListener::local_addr unimplemented on redox"))
584615
}
@@ -594,6 +625,7 @@ impl UnixListener {
594625
///
595626
/// listener.set_nonblocking(true).expect("Couldn't set non blocking");
596627
/// ```
628+
#[stable(feature = "unix_socket_redox", since = "1.29")]
597629
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
598630
self.0.set_nonblocking(nonblocking)
599631
}
@@ -614,6 +646,7 @@ impl UnixListener {
614646
///
615647
/// # Platform specific
616648
/// On Redox this always returns None.
649+
#[stable(feature = "unix_socket_redox", since = "1.29")]
617650
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
618651
Ok(None)
619652
}
@@ -649,29 +682,34 @@ impl UnixListener {
649682
/// }
650683
/// }
651684
/// ```
685+
#[stable(feature = "unix_socket_redox", since = "1.29")]
652686
pub fn incoming<'a>(&'a self) -> Incoming<'a> {
653687
Incoming { listener: self }
654688
}
655689
}
656690

691+
#[stable(feature = "unix_socket_redox", since = "1.29")]
657692
impl AsRawFd for UnixListener {
658693
fn as_raw_fd(&self) -> RawFd {
659694
self.0.raw()
660695
}
661696
}
662697

698+
#[stable(feature = "unix_socket_redox", since = "1.29")]
663699
impl FromRawFd for UnixListener {
664700
unsafe fn from_raw_fd(fd: RawFd) -> UnixListener {
665701
UnixListener(FileDesc::new(fd))
666702
}
667703
}
668704

705+
#[stable(feature = "unix_socket_redox", since = "1.29")]
669706
impl IntoRawFd for UnixListener {
670707
fn into_raw_fd(self) -> RawFd {
671708
self.0.into_raw()
672709
}
673710
}
674711

712+
#[stable(feature = "unix_socket_redox", since = "1.29")]
675713
impl<'a> IntoIterator for &'a UnixListener {
676714
type Item = io::Result<UnixStream>;
677715
type IntoIter = Incoming<'a>;
@@ -712,10 +750,12 @@ impl<'a> IntoIterator for &'a UnixListener {
712750
/// }
713751
/// ```
714752
#[derive(Debug)]
753+
#[stable(feature = "unix_socket_redox", since = "1.29")]
715754
pub struct Incoming<'a> {
716755
listener: &'a UnixListener,
717756
}
718757

758+
#[stable(feature = "unix_socket_redox", since = "1.29")]
719759
impl<'a> Iterator for Incoming<'a> {
720760
type Item = io::Result<UnixStream>;
721761

0 commit comments

Comments
 (0)