File tree Expand file tree Collapse file tree 3 files changed +16
-11
lines changed Expand file tree Collapse file tree 3 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,16 @@ impl FileDesc {
48
48
cvt ( libc:: write ( self . fd , buf) )
49
49
}
50
50
51
+ pub fn duplicate ( & self ) -> io:: Result < FileDesc > {
52
+ let new_fd = cvt ( libc:: dup ( self . fd , & [ ] ) ) ?;
53
+ Ok ( FileDesc :: new ( new_fd) )
54
+ }
55
+
56
+ pub fn nonblocking ( & self ) -> io:: Result < bool > {
57
+ let flags = cvt ( libc:: fcntl ( self . fd , libc:: F_GETFL , 0 ) ) ?;
58
+ Ok ( flags & libc:: O_NONBLOCK == libc:: O_NONBLOCK )
59
+ }
60
+
51
61
pub fn set_cloexec ( & self ) -> io:: Result < ( ) > {
52
62
let mut flags = cvt ( libc:: fcntl ( self . fd , libc:: F_GETFL , 0 ) ) ?;
53
63
flags |= libc:: O_CLOEXEC ;
@@ -63,11 +73,6 @@ impl FileDesc {
63
73
}
64
74
cvt ( libc:: fcntl ( self . fd , libc:: F_SETFL , flags) ) . and ( Ok ( ( ) ) )
65
75
}
66
-
67
- pub fn duplicate ( & self ) -> io:: Result < FileDesc > {
68
- let new_fd = cvt ( libc:: dup ( self . fd , & [ ] ) ) ?;
69
- Ok ( FileDesc :: new ( new_fd) )
70
- }
71
76
}
72
77
73
78
impl < ' a > Read for & ' a FileDesc {
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ impl TcpStream {
58
58
}
59
59
60
60
pub fn nonblocking ( & self ) -> Result < bool > {
61
- Err ( Error :: new ( ErrorKind :: Other , "TcpStream::nonblocking not implemented" ) )
61
+ self . 0 . fd ( ) . nonblocking ( )
62
62
}
63
63
64
64
pub fn only_v6 ( & self ) -> Result < bool > {
@@ -81,8 +81,8 @@ impl TcpStream {
81
81
Err ( Error :: new ( ErrorKind :: Other , "TcpStream::set_nodelay not implemented" ) )
82
82
}
83
83
84
- pub fn set_nonblocking ( & self , _nonblocking : bool ) -> Result < ( ) > {
85
- Err ( Error :: new ( ErrorKind :: Other , "TcpStream::set_nonblocking not implemented" ) )
84
+ pub fn set_nonblocking ( & self , nonblocking : bool ) -> Result < ( ) > {
85
+ self . 0 . fd ( ) . set_nonblocking ( nonblocking )
86
86
}
87
87
88
88
pub fn set_only_v6 ( & self , _only_v6 : bool ) -> Result < ( ) > {
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ impl UdpSocket {
90
90
}
91
91
92
92
pub fn nonblocking ( & self ) -> Result < bool > {
93
- Err ( Error :: new ( ErrorKind :: Other , "UdpSocket::nonblocking not implemented" ) )
93
+ self . 0 . fd ( ) . nonblocking ( )
94
94
}
95
95
96
96
pub fn only_v6 ( & self ) -> Result < bool > {
@@ -125,8 +125,8 @@ impl UdpSocket {
125
125
Err ( Error :: new ( ErrorKind :: Other , "UdpSocket::set_multicast_ttl_v4 not implemented" ) )
126
126
}
127
127
128
- pub fn set_nonblocking ( & self , _nonblocking : bool ) -> Result < ( ) > {
129
- Err ( Error :: new ( ErrorKind :: Other , "UdpSocket::set_nonblocking not implemented" ) )
128
+ pub fn set_nonblocking ( & self , nonblocking : bool ) -> Result < ( ) > {
129
+ self . 0 . fd ( ) . set_nonblocking ( nonblocking )
130
130
}
131
131
132
132
pub fn set_only_v6 ( & self , _only_v6 : bool ) -> Result < ( ) > {
You can’t perform that action at this time.
0 commit comments