From 02b1117dca1c1e1fcc700bff4d6a93c33bfbc7d8 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 12 Nov 2020 20:07:43 -0800 Subject: 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 --- tokio/src/macros/cfg.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tokio/src/macros') 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)*) => { $( -- cgit v1.2.3