8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- #![ unstable ( feature = "unix_socket_redox" , reason = "new feature" , issue= "51553 ") ]
11
+ #![ stable ( feature = "unix_socket_redox" , since = "1.29 " ) ]
12
12
13
13
//! Unix-specific networking functionality
14
14
@@ -37,6 +37,7 @@ use sys::{cvt, fd::FileDesc, syscall};
37
37
/// let addr = socket.local_addr().expect("Couldn't get local address");
38
38
/// ```
39
39
#[ derive( Clone ) ]
40
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
40
41
pub struct SocketAddr ( ( ) ) ;
41
42
42
43
impl SocketAddr {
@@ -64,6 +65,7 @@ impl SocketAddr {
64
65
/// let addr = socket.local_addr().expect("Couldn't get local address");
65
66
/// assert_eq!(addr.as_pathname(), None);
66
67
/// ```
68
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
67
69
pub fn as_pathname ( & self ) -> Option < & Path > {
68
70
None
69
71
}
@@ -91,10 +93,12 @@ impl SocketAddr {
91
93
/// let addr = socket.local_addr().expect("Couldn't get local address");
92
94
/// assert_eq!(addr.is_unnamed(), true);
93
95
/// ```
96
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
94
97
pub fn is_unnamed ( & self ) -> bool {
95
98
false
96
99
}
97
100
}
101
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
98
102
impl fmt:: Debug for SocketAddr {
99
103
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
100
104
write ! ( fmt, "SocketAddr" )
@@ -115,8 +119,10 @@ impl fmt::Debug for SocketAddr {
115
119
/// stream.read_to_string(&mut response).unwrap();
116
120
/// println!("{}", response);
117
121
/// ```
122
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
118
123
pub struct UnixStream ( FileDesc ) ;
119
124
125
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
120
126
impl fmt:: Debug for UnixStream {
121
127
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
122
128
let mut builder = fmt. debug_struct ( "UnixStream" ) ;
@@ -147,6 +153,7 @@ impl UnixStream {
147
153
/// }
148
154
/// };
149
155
/// ```
156
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
150
157
pub fn connect < P : AsRef < Path > > ( path : P ) -> io:: Result < UnixStream > {
151
158
if let Some ( s) = path. as_ref ( ) . to_str ( ) {
152
159
cvt ( syscall:: open ( format ! ( "chan:{}" , s) , syscall:: O_CLOEXEC ) )
@@ -177,6 +184,7 @@ impl UnixStream {
177
184
/// }
178
185
/// };
179
186
/// ```
187
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
180
188
pub fn pair ( ) -> io:: Result < ( UnixStream , UnixStream ) > {
181
189
let server = cvt ( syscall:: open ( "chan:" , syscall:: O_CREAT | syscall:: O_CLOEXEC ) )
182
190
. map ( FileDesc :: new) ?;
@@ -200,6 +208,7 @@ impl UnixStream {
200
208
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
201
209
/// let sock_copy = socket.try_clone().expect("Couldn't clone socket");
202
210
/// ```
211
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
203
212
pub fn try_clone ( & self ) -> io:: Result < UnixStream > {
204
213
self . 0 . duplicate ( ) . map ( UnixStream )
205
214
}
@@ -214,6 +223,7 @@ impl UnixStream {
214
223
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
215
224
/// let addr = socket.local_addr().expect("Couldn't get local address");
216
225
/// ```
226
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
217
227
pub fn local_addr ( & self ) -> io:: Result < SocketAddr > {
218
228
Err ( Error :: new ( ErrorKind :: Other , "UnixStream::local_addr unimplemented on redox" ) )
219
229
}
@@ -228,6 +238,7 @@ impl UnixStream {
228
238
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
229
239
/// let addr = socket.peer_addr().expect("Couldn't get peer address");
230
240
/// ```
241
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
231
242
pub fn peer_addr ( & self ) -> io:: Result < SocketAddr > {
232
243
Err ( Error :: new ( ErrorKind :: Other , "UnixStream::peer_addr unimplemented on redox" ) )
233
244
}
@@ -266,6 +277,7 @@ impl UnixStream {
266
277
/// let err = result.unwrap_err();
267
278
/// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
268
279
/// ```
280
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
269
281
pub fn set_read_timeout ( & self , _timeout : Option < Duration > ) -> io:: Result < ( ) > {
270
282
Err ( Error :: new ( ErrorKind :: Other , "UnixStream::set_read_timeout unimplemented on redox" ) )
271
283
}
@@ -304,6 +316,7 @@ impl UnixStream {
304
316
/// let err = result.unwrap_err();
305
317
/// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
306
318
/// ```
319
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
307
320
pub fn set_write_timeout ( & self , _timeout : Option < Duration > ) -> io:: Result < ( ) > {
308
321
Err ( Error :: new ( ErrorKind :: Other , "UnixStream::set_write_timeout unimplemented on redox" ) )
309
322
}
@@ -320,6 +333,7 @@ impl UnixStream {
320
333
/// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
321
334
/// assert_eq!(socket.read_timeout().unwrap(), Some(Duration::new(1, 0)));
322
335
/// ```
336
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
323
337
pub fn read_timeout ( & self ) -> io:: Result < Option < Duration > > {
324
338
Err ( Error :: new ( ErrorKind :: Other , "UnixStream::read_timeout unimplemented on redox" ) )
325
339
}
@@ -336,6 +350,7 @@ impl UnixStream {
336
350
/// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout");
337
351
/// assert_eq!(socket.write_timeout().unwrap(), Some(Duration::new(1, 0)));
338
352
/// ```
353
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
339
354
pub fn write_timeout ( & self ) -> io:: Result < Option < Duration > > {
340
355
Err ( Error :: new ( ErrorKind :: Other , "UnixStream::write_timeout unimplemented on redox" ) )
341
356
}
@@ -350,6 +365,7 @@ impl UnixStream {
350
365
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
351
366
/// socket.set_nonblocking(true).expect("Couldn't set nonblocking");
352
367
/// ```
368
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
353
369
pub fn set_nonblocking ( & self , nonblocking : bool ) -> io:: Result < ( ) > {
354
370
self . 0 . set_nonblocking ( nonblocking)
355
371
}
@@ -369,6 +385,7 @@ impl UnixStream {
369
385
///
370
386
/// # Platform specific
371
387
/// On Redox this always returns None.
388
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
372
389
pub fn take_error ( & self ) -> io:: Result < Option < io:: Error > > {
373
390
Ok ( None )
374
391
}
@@ -390,11 +407,13 @@ impl UnixStream {
390
407
/// let socket = UnixStream::connect("/tmp/sock").unwrap();
391
408
/// socket.shutdown(Shutdown::Both).expect("shutdown function failed");
392
409
/// ```
410
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
393
411
pub fn shutdown ( & self , _how : Shutdown ) -> io:: Result < ( ) > {
394
412
Err ( Error :: new ( ErrorKind :: Other , "UnixStream::shutdown unimplemented on redox" ) )
395
413
}
396
414
}
397
415
416
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
398
417
impl io:: Read for UnixStream {
399
418
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
400
419
io:: Read :: read ( & mut & * self , buf)
@@ -406,6 +425,7 @@ impl io::Read for UnixStream {
406
425
}
407
426
}
408
427
428
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
409
429
impl < ' a > io:: Read for & ' a UnixStream {
410
430
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
411
431
self . 0 . read ( buf)
@@ -417,6 +437,7 @@ impl<'a> io::Read for &'a UnixStream {
417
437
}
418
438
}
419
439
440
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
420
441
impl io:: Write for UnixStream {
421
442
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
422
443
io:: Write :: write ( & mut & * self , buf)
@@ -427,6 +448,7 @@ impl io::Write for UnixStream {
427
448
}
428
449
}
429
450
451
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
430
452
impl < ' a > io:: Write for & ' a UnixStream {
431
453
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
432
454
self . 0 . write ( buf)
@@ -437,18 +459,21 @@ impl<'a> io::Write for &'a UnixStream {
437
459
}
438
460
}
439
461
462
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
440
463
impl AsRawFd for UnixStream {
441
464
fn as_raw_fd ( & self ) -> RawFd {
442
465
self . 0 . raw ( )
443
466
}
444
467
}
445
468
469
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
446
470
impl FromRawFd for UnixStream {
447
471
unsafe fn from_raw_fd ( fd : RawFd ) -> UnixStream {
448
472
UnixStream ( FileDesc :: new ( fd) )
449
473
}
450
474
}
451
475
476
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
452
477
impl IntoRawFd for UnixStream {
453
478
fn into_raw_fd ( self ) -> RawFd {
454
479
self . 0 . into_raw ( )
@@ -483,8 +508,10 @@ impl IntoRawFd for UnixStream {
483
508
/// }
484
509
/// }
485
510
/// ```
511
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
486
512
pub struct UnixListener ( FileDesc ) ;
487
513
514
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
488
515
impl fmt:: Debug for UnixListener {
489
516
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
490
517
let mut builder = fmt. debug_struct ( "UnixListener" ) ;
@@ -512,6 +539,7 @@ impl UnixListener {
512
539
/// }
513
540
/// };
514
541
/// ```
542
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
515
543
pub fn bind < P : AsRef < Path > > ( path : P ) -> io:: Result < UnixListener > {
516
544
if let Some ( s) = path. as_ref ( ) . to_str ( ) {
517
545
cvt ( syscall:: open ( format ! ( "chan:{}" , s) , syscall:: O_CREAT | syscall:: O_CLOEXEC ) )
@@ -545,6 +573,7 @@ impl UnixListener {
545
573
/// Err(e) => println!("accept function failed: {:?}", e),
546
574
/// }
547
575
/// ```
576
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
548
577
pub fn accept ( & self ) -> io:: Result < ( UnixStream , SocketAddr ) > {
549
578
self . 0 . duplicate_path ( b"listen" ) . map ( |fd| ( UnixStream ( fd) , SocketAddr ( ( ) ) ) )
550
579
}
@@ -564,6 +593,7 @@ impl UnixListener {
564
593
///
565
594
/// let listener_copy = listener.try_clone().expect("try_clone failed");
566
595
/// ```
596
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
567
597
pub fn try_clone ( & self ) -> io:: Result < UnixListener > {
568
598
self . 0 . duplicate ( ) . map ( UnixListener )
569
599
}
@@ -579,6 +609,7 @@ impl UnixListener {
579
609
///
580
610
/// let addr = listener.local_addr().expect("Couldn't get local address");
581
611
/// ```
612
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
582
613
pub fn local_addr ( & self ) -> io:: Result < SocketAddr > {
583
614
Err ( Error :: new ( ErrorKind :: Other , "UnixListener::local_addr unimplemented on redox" ) )
584
615
}
@@ -594,6 +625,7 @@ impl UnixListener {
594
625
///
595
626
/// listener.set_nonblocking(true).expect("Couldn't set non blocking");
596
627
/// ```
628
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
597
629
pub fn set_nonblocking ( & self , nonblocking : bool ) -> io:: Result < ( ) > {
598
630
self . 0 . set_nonblocking ( nonblocking)
599
631
}
@@ -614,6 +646,7 @@ impl UnixListener {
614
646
///
615
647
/// # Platform specific
616
648
/// On Redox this always returns None.
649
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
617
650
pub fn take_error ( & self ) -> io:: Result < Option < io:: Error > > {
618
651
Ok ( None )
619
652
}
@@ -649,29 +682,34 @@ impl UnixListener {
649
682
/// }
650
683
/// }
651
684
/// ```
685
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
652
686
pub fn incoming < ' a > ( & ' a self ) -> Incoming < ' a > {
653
687
Incoming { listener : self }
654
688
}
655
689
}
656
690
691
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
657
692
impl AsRawFd for UnixListener {
658
693
fn as_raw_fd ( & self ) -> RawFd {
659
694
self . 0 . raw ( )
660
695
}
661
696
}
662
697
698
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
663
699
impl FromRawFd for UnixListener {
664
700
unsafe fn from_raw_fd ( fd : RawFd ) -> UnixListener {
665
701
UnixListener ( FileDesc :: new ( fd) )
666
702
}
667
703
}
668
704
705
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
669
706
impl IntoRawFd for UnixListener {
670
707
fn into_raw_fd ( self ) -> RawFd {
671
708
self . 0 . into_raw ( )
672
709
}
673
710
}
674
711
712
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
675
713
impl < ' a > IntoIterator for & ' a UnixListener {
676
714
type Item = io:: Result < UnixStream > ;
677
715
type IntoIter = Incoming < ' a > ;
@@ -712,10 +750,12 @@ impl<'a> IntoIterator for &'a UnixListener {
712
750
/// }
713
751
/// ```
714
752
#[ derive( Debug ) ]
753
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
715
754
pub struct Incoming < ' a > {
716
755
listener : & ' a UnixListener ,
717
756
}
718
757
758
+ #[ stable( feature = "unix_socket_redox" , since = "1.29" ) ]
719
759
impl < ' a > Iterator for Incoming < ' a > {
720
760
type Item = io:: Result < UnixStream > ;
721
761
0 commit comments