summaryrefslogtreecommitdiffstats
path: root/tokio/src/io
AgeCommit message (Collapse)Author
2020-12-06net: add TcpStream::into_std (#3189)Fuyang Liu
2020-11-30io: add AsyncFd::with_interest (#3167)HK416-is-all-you-need
Fixes #3072
2020-11-18io: add vectored writes to `AsyncWrite` (#3149)Sean McArthur
This adds `AsyncWrite::poll_write_vectored`, and implements it for `TcpStream` and `UnixStream`. Refs: #3135.
2020-11-12net: add TcpStream::ready and non-blocking ops (#3130)Carl Lerche
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
2020-11-11io: driver internal cleanup (#3124)Carl Lerche
* Removes duplicated code by moving it to `Registration`. * impl `Deref` for `PollEvented` to avoid `get_ref()`. * Avoid extra waker clones in I/O driver. * Add `Interest` wrapper around `mio::Interest`.
2020-11-10io: update AsyncFd to use Registration (#3113)Carl Lerche
2020-11-07async_fd: make into_inner() deregister the fd (#3104)bdonlan
* async_fd: make into_inner() deregister the fd Fixes: #3103 * make clippy happy Co-authored-by: Bryan Donlan <bdonlan@amazon.com>
2020-10-27Revert "util: upgrade tokio-util to bytes 0.6 (#3052)" (#3060)Carl Lerche
This reverts commit fe2b997. We are avoiding adding poll_read_buf to tokio itself for now. The patch is reverted now in order to not block the v0.3.2 release (#3059).
2020-10-27util: upgrade tokio-util to bytes 0.6 (#3052)Dirkjan Ochtman
2020-10-24io: expand on de-initialization of ReadBuf (#3035)Alice Ryhl
2020-10-22io: Add AsyncFd, fix io::driver shutdown (#2903)bdonlan
* io: Add AsyncFd This adds AsyncFd, a unix-only structure to allow for read/writability states to be monitored for arbitrary file descriptors. Issue: #2728 * driver: fix shutdown notification unreliability Previously, there was a race window in which an IO driver shutting down could fail to notify ScheduledIo instances of this state; in particular, notification of outstanding ScheduledIo registrations was driven by `Driver::drop`, but registrations bypass `Driver` and go directly to a `Weak<Inner>`. The `Driver` holds the `Arc<Inner>` keeping `Inner` alive, but it's possible that a new handle could be registered (or a new readiness future created for an existing handle) after the `Driver::drop` handler runs and prior to `Inner` being dropped. This change fixes this in two parts: First, notification of outstanding ScheduledIo handles is pushed down into the drop method of `Inner` instead, and, second, we add state to ScheduledIo to ensure that we remember that the IO driver we're bound to has shut down after the initial shutdown notification, so that subsequent readiness future registrations can immediately return (instead of potentially blocking indefinitely). Fixes: #2924
2020-10-21io: add `AsyncReadExt::read_buf` (#3003)Carl Lerche
Brings back `read_buf` from 0.2. This will be stabilized as part of 1.0.
2020-10-21io: explain how to determine number of bytes read in AsyncRead (#3011)Zahari Dichev
Fixes: #2999
2020-10-19io: add copy_buf (#2884)Zahari Dichev
2020-10-16Update documentation of AsyncRead to reflect use of ReadBufJohn-John Tedro
2020-10-12rt: simplify rt-* features (#2949)Taiki Endo
tokio: merge rt-core and rt-util as rt rename rt-threaded to rt-multi-thread tokio-util: rename rt-core to rt Closes #2942
2020-10-13net: merge tcp, udp, uds features to net feature (#2943)Taiki Endo
2020-10-12rt: Remove `threaded_scheduler()` and `basic_scheduler()` (#2876)Lucio Franco
Co-authored-by: Alice Ryhl <alice@ryhl.io> Co-authored-by: Carl Lerche <me@carllerche.com>
2020-10-12io: Rename `ReadBuf` methods (#2945)Lucio Franco
This changes `ReadBuf::add_filled` to `ReadBuf::advance` and `ReadBuf::append` to `ReadBuf::put_slice`. This is just a mechanical change. Closes #2769
2020-10-09io: make Seek and Copy private (#2935)Taiki Endo
Refs: #2928
2020-10-08net: use &self with TcpListener::accept (#2919)Carl Lerche
Uses the infrastructure added by #2828 to enable switching `TcpListener::accept` to use `&self`. This also switches `poll_accept` to use `&self`. While doing introduces a hazard, `poll_*` style functions are considered low-level. Most users will use the `async fn` variants which are more misuse-resistant. TcpListener::incoming() is temporarily removed as it has the same problem as `TcpSocket::by_ref()` and will be implemented later.
2020-10-08io: remove Poll from the AsyncSeek::start_seek return value (#2885)Zahari Dichev
2020-10-06io, stream: assert !Unpin for ext trait futures (#2913)Taiki Endo
2020-10-05io, stream: make ext trait futures !Unpin (#2910)Taiki Endo
Make these future `!Unpin` for compatibility with async trait methods.
2020-10-05io: optimize writing large buffers to windows stdio (#2888)Mikail Bagishov
2020-10-02io: update to Mio 0.7 (#2893)Carl Lerche
This also makes Mio an implementation detail, removing it from the public API. This is based on #1767.
2020-10-01chore: make #[doc(hidden)] apis private (#2901)Alice Ryhl
2020-09-25Fix readiness future eagerly consuming entire socket readiness (#2887)Sean McArthur
In the `readiness` future, before inserting a waiter into the list, the current socket readiness is eagerly checked. However, it would return as a `ReadyEvent` the entire socket readiness, instead of just the interest desired from `readiness(interest)`. This would result in the later call to `clear_readiness(event)` removing all of it. Closes #2886
2020-09-25chore: handle std `Mutex` poisoning in a shim (#2872)Zahari Dichev
As tokio does not rely on poisoning, we can avoid always unwrapping when locking by handling the `PoisonError` in the Mutex shim. Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
2020-09-24io: remove poll_{read,write}_buf from traits (#2882)Carl Lerche
These functions have object safety issues. It also has been decided to avoid vectored operations on the I/O traits. A later PR will bring back vectored operations on specific types that support them. Refs: #2879, #2716
2020-09-24chore: remove internal io-readiness cargo feature (#2878)Ivan Petkov
2020-09-24docs: use #[doc(no_inline)] on re-exports (#2874)Taiki Endo
2020-09-23io: use intrusive wait list for I/O driver (#2828)Sean McArthur
This refactors I/O registration in a few ways: - Cleans up the cached readiness in `PollEvented`. This cache used to be helpful when readiness was a linked list of `*mut Node`s in `Registration`. Previous refactors have turned `Registration` into just an `AtomicUsize` holding the current readiness, so the cache is just extra work and complexity. Gone. - Polling the `Registration` for readiness now gives a `ReadyEvent`, which includes the driver tick. This event must be passed back into `clear_readiness`, so that the readiness is only cleared from `Registration` if the tick hasn't changed. Previously, it was possible to clear the readiness even though another thread had *just* polled the driver and found the socket ready again. - Registration now also contains an `async fn readiness`, which stores wakers in an instrusive linked list. This allows an unbounded number of tasks to register for readiness (previously, only 1 per direction (read and write)). By using the intrusive linked list, there is no concern of leaking the storage of the wakers, since they are stored inside the `async fn` and released when the future is dropped. - Registration retains a `poll_readiness(Direction)` method, to support `AsyncRead` and `AsyncWrite`. They aren't able to use `async fn`s, and so there are 2 reserved slots for those methods. - IO types where it makes sense to have multiple tasks waiting on them now take advantage of this new `async fn readiness`, such as `UdpSocket` and `UnixDatagram`. Additionally, this makes the `io-driver` "feature" internal-only (no longer documented, not part of public API), and adds a second internal-only feature, `io-readiness`, to group together linked list part of registration that is only used by some of the IO types. After a bit of discussion, changing stream-based transports (like `TcpStream`) to have `async fn read(&self)` is punted, since that is likely too easy of a footgun to activate. Refs: #2779, #2728
2020-09-23io: move #[cfg(not(loom))] to fix warning (#2864)Alice Ryhl
2020-09-23io: fix stdout and stderr buffering on windows (#2734)Mikail Bagishov
2020-09-22signal: move driver to runtime thread (#2835)Ivan Petkov
Refactors the signal infrastructure to move the driver to the runtime thread. This follows the model put forth by the I/O driver and time driver.
2020-09-19io: fix doc-cfg on AsyncSeekExt (#2846)Taiki Endo
2020-09-13doc: fix some links (#2834)Alice Ryhl
2020-09-08io: move StreamReader and ReaderStream into tokio_util (#2788)Alice Ryhl
Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru> Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-09-05io: add `ReadBuf::take` (#2817)Zahari Dichev
Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
2020-08-27rt: Refactor `Runtime::block_on` to take `&self` (#2782)Lucio Franco
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-08-13io: change AsyncRead to use a ReadBuf (#2758)Sean McArthur
Works towards #2716. Changes the argument to `AsyncRead::poll_read` to take a `ReadBuf` struct that safely manages writes to uninitialized memory.
2020-08-11io: rewrite slab to support compaction (#2757)Carl Lerche
The I/O driver uses a slab to store per-resource state. Doing this provides two benefits. First, allocating state is streamlined. Second, resources may be safely indexed using a `usize` type. The `usize` is used passed to the OS's selector when registering for receiving events. The original slab implementation used a `Vec` backed by `RwLock`. This primarily caused contention when reading state. This implementation also only **grew** the slab capacity but never shrank. In #1625, the slab was rewritten to use a lock-free strategy. The lock contention was removed but this implementation was still grow-only. This change adds the ability to release memory. Similar to the previous implementation, it structures the slab to use a vector of pages. This enables growing the slab without having to move any previous entries. It also adds the ability to release pages. This is done by introducing a lock when allocating/releasing slab entries. This does not impact benchmarks, primarily due to the existing implementation not being "done" and also having a lock around allocating and releasing. A `Slab::compact()` function is added. Pages are iterated. When a page is found with no slots in use, the page is freed. The `compact()` function is called occasionally by the I/O driver. Fixes #2505
2020-08-09io: use stderr in stderr documentation (#2746)Cameron Taggart
2020-07-28rt: fix potential leak during runtime shutdown (#2649)Émile Grégoire
JoinHandle of threads created by the pool are now tracked and properly joined at shutdown. If the thread does not return within the timeout, then it's not joined and left to the OS for cleanup. Also, break a cycle between wakers held by the timer and the runtime. Fixes #2641, #2535
2020-07-28io: rewrite read_to_end and read_to_string (#2560)Alice Ryhl
The new implementation changes the behavior such that set_len is called after poll_read. The motivation of this change is that it makes it much more obvious that a rouge panic won't give the caller access to a vector containing exposed uninitialized memory. The new implementation also makes sure to not zero memory twice. Additionally, it makes the various implementations more consistent with each other regarding the naming of variables, and whether we store how many bytes we have read, or how many were in the container originally. Fixes: #2544
2020-07-24chore: complete CI migration to Github Actions (#2680)Carl Lerche
2020-07-24net: ensure that unix sockets have both split and into_split (#2687)Alice Ryhl
The documentation build failed with errors such as error: `[read]` public documentation for `take` links to a private item --> tokio/src/io/util/async_read_ext.rs:1078:9 | 1078 | / /// Creates an adaptor which reads at most `limit` bytes from it. 1079 | | /// 1080 | | /// This function returns a new instance of `AsyncRead` which will read 1081 | | /// at most `limit` bytes, after which it will always return EOF ... | 1103 | | /// } 1104 | | /// ``` | |_______________^ | note: the lint level is defined here --> tokio/src/lib.rs:13:9 | 13 | #![deny(intra_doc_link_resolution_failure)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: the link appears in this line: bytes read and future calls to [`read()`][read] may succeed.
2020-07-23io: always re-export std::io (#2606)Taiki Endo
2020-07-22io: add `io::duplex()` as bidirectional reader/writer (#2661)Sean McArthur
`duplex` returns a pair of connected `DuplexStream`s. `DuplexStream` is a bidirectional type that can be used to simulate IO, but over an in-process piece of memory.