diff options
author | Carl Lerche <me@carllerche.com> | 2020-11-12 20:07:43 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-12 20:07:43 -0800 |
commit | 02b1117dca1c1e1fcc700bff4d6a93c33bfbc7d8 (patch) | |
tree | 95788ea2d89de4af6021befa70a3f5d80034578a /tokio/src/macros | |
parent | 685da8dadd8821d1053ce7ecaf01ab5ee231bef9 (diff) |
net: add TcpStream::ready and non-blocking ops (#3130)
Adds function to await for readiness on the TcpStream and non-blocking read/write functions.
`async fn TcpStream::ready(Interest)` waits for socket readiness satisfying **any** of the specified
interest. There are also two shorthand functions, `readable()` and `writable()`.
Once the stream is in a ready state, the caller may perform non-blocking operations on it using
`try_read()` and `try_write()`. These function return `WouldBlock` if the stream is not, in fact, ready.
The await readiness function are similar to `AsyncFd`, but do not require a guard. The guard in
`AsyncFd` protect against a potential race between receiving the readiness notification and clearing
it. The guard is needed as Tokio does not control the operations. With `TcpStream`, the `try_read()`
and `try_write()` function handle clearing stream readiness as needed.
This also exposes `Interest` and `Ready`, both defined in Tokio as wrappers for Mio types. These
types will also be useful for fixing #3072 .
Other I/O types, such as `TcpListener`, `UdpSocket`, `Unix*` should get similar functions, but this
is left for later PRs.
Refs: #3130
Diffstat (limited to 'tokio/src/macros')
-rw-r--r-- | tokio/src/macros/cfg.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs index edf681a4..15216560 100644 --- a/tokio/src/macros/cfg.rs +++ b/tokio/src/macros/cfg.rs @@ -79,6 +79,19 @@ macro_rules! cfg_io_driver { } } +macro_rules! cfg_io_driver_impl { + ( $( $item:item )* ) => { + $( + #[cfg(any( + feature = "net", + feature = "process", + all(unix, feature = "signal"), + ))] + $item + )* + } +} + macro_rules! cfg_not_io_driver { ($($item:item)*) => { $( |