@@ -31,18 +31,18 @@ expose functionality like `set_nodelay`:
31
31
``` rust
32
32
impl TcpStream {
33
33
pub fn set_read_timeout (& self , dur : Option <Duration >) -> io :: Result <()> { ... }
34
- pub fn read_timeout (& self ) -> Option <Duration >;
34
+ pub fn read_timeout (& self ) -> io :: Result < Option <Duration > >;
35
35
36
36
pub fn set_write_timeout (& self , dur : Option <Duration >) -> io :: Result <()> { ... }
37
- pub fn write_timeout (& self ) -> Option <Duration >;
37
+ pub fn write_timeout (& self ) -> io :: Result < Option <Duration > >;
38
38
}
39
39
40
40
impl UdpSocket {
41
41
pub fn set_read_timeout (& self , dur : Option <Duration >) -> io :: Result <()> { ... }
42
- pub fn read_timeout (& self ) -> Option <Duration >;
42
+ pub fn read_timeout (& self ) -> io :: Result < Option <Duration > >;
43
43
44
44
pub fn set_write_timeout (& self , dur : Option <Duration >) -> io :: Result <()> { ... }
45
- pub fn write_timeout (& self ) -> Option <Duration >;
45
+ pub fn write_timeout (& self ) -> io :: Result < Option <Duration > >;
46
46
}
47
47
```
48
48
@@ -93,6 +93,25 @@ Aside from fitting Rust idioms better, the main proposal also gives a
93
93
somewhat stronger indication of a bug when things go wrong (rather
94
94
than simply failing to time out, for example).
95
95
96
+ ## Combining with nonblocking support
97
+
98
+ Another possibility would be to provide a single method that can
99
+ choose between blocking indefinitely, blocking with a timeout, and
100
+ nonblocking mode:
101
+
102
+ ``` rust
103
+ enum BlockingMode {
104
+ Nonblocking ,
105
+ Blocking ,
106
+ Timeout (Duration )
107
+ }
108
+ ```
109
+
110
+ This ` enum ` makes clear that it doesn't make sense to have both a
111
+ timeout and put the socket in nonblocking mode. On the other hand, it
112
+ would relinquish the one-to-one correspondence between Rust
113
+ configuration APIs and underlying socket options.
114
+
96
115
## Wrapping for compositionality
97
116
98
117
A different approach would be to * wrap* socket types with a "timeout
0 commit comments