Skip to content

Commit 390b78c

Browse files
committed
Added Result for reading timeout; added enum alternative
1 parent e44bbba commit 390b78c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

text/0000-socket-timeouts.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ expose functionality like `set_nodelay`:
3131
```rust
3232
impl TcpStream {
3333
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>>;
3535

3636
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>>;
3838
}
3939

4040
impl UdpSocket {
4141
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>>;
4343

4444
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>>;
4646
}
4747
```
4848

@@ -93,6 +93,25 @@ Aside from fitting Rust idioms better, the main proposal also gives a
9393
somewhat stronger indication of a bug when things go wrong (rather
9494
than simply failing to time out, for example).
9595

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+
96115
## Wrapping for compositionality
97116

98117
A different approach would be to *wrap* socket types with a "timeout

0 commit comments

Comments
 (0)