189 Commits

Author SHA1 Message Date
hu-kai45 6e63b18c62 tokio 版本升级到 1.25.0
Signed-off-by: hu-kai45 <hukai45@huawei.com>
2023-06-25 16:23:23 +08:00
peizhe 1a39245f61 Add GN Build Files and Custom Modifications to Rust Third-party Libraries
Signed-off-by: peizhe <472708703@qq.com>
2023-04-18 18:25:37 +08:00
Hayden Stainsby 4e7454c48d util: add track_caller to public APIs (#4785)
* util: add track_caller to public APIs

Functions that may panic can be annotated with `#[track_caller]` so that
in the event of a panic, the function where the user called the
panicking function is shown instead of the file and line within Tokio
source.

This change adds `#[track_caller]` to all the non-unstable public APIs in
tokio-util where the documentation describes how the function may panic
due to incorrect context or inputs.

In one place, an assert was added where the described behavior appeared
not to be implemented. The documentation for `DelayQueue::reserve`
states that the function will panic if the new capacity exceeds the
maximum number of entries the queue can contain. However, the function
didn't panic until a higher number caused by an allocation failure. This
is inconsistent with `DelayQueue::insert_at` which will panic if the
number of entries were to go over MAX_ENTRIES.

Tests are included to cover each potentially panicking function.

Refs: #4413

* fix tests on FreeBSD 32-bit (I hope)

Some tests were failing on FreeBSD 32-bit because the "times too far in
the future" for DelayQueue were also too far in the future for the OS.

Fixed by copying the MAX_DURATION value from where it's defined and
using it to create a duration that is just 1 more than the maximum. This
will start to break once we get close (within 2 and a bit years) of the
Epochalypse (19 Jan, 2038) - but a lot of other things are going to be
breaking on FreeBSD 32-bit by then anyway.
2022-06-27 12:31:31 +02:00
b-naber 43c82e8fbd task: improve LocalPoolHandle (#4680) 2022-06-17 18:37:00 +02:00
Richard Zak 7c95084f54 chore: fix spelling (#4769)
Signed-off-by: Richard Zak <richard@profian.com>
2022-06-15 16:06:50 +00:00
David Barsky 0e63c6240a joinset: rename join_one to join_next (#4755) 2022-06-09 22:41:25 +02:00
Alice Ryhl 4bdf2a4f86 chore: prepare tokio-util 0.7.3 (#4744) 2022-06-04 22:04:02 +02:00
Alice Ryhl d49bce3fb7 task: update return value of JoinSet::join_one (#4726) 2022-05-31 09:15:37 +02:00
Eliza Weisman d7664c583b task: add #[track_caller] to JoinSet/JoinMap (#4697)
## Motivation

Currently, the various spawning methods on `tokio::task::JoinSet` and
`tokio_util::task::JoinMap` lack `#[track_caller]` attributes, so the
`tracing` spans generated for tasks spawned on `JoinSet`s/`JoinMap`s
will have the `JoinSet` spawning method as their spawn location, rather
than the user code that called that method.

## Solution

This PR fixes that by...adding a bunch of `#[track_caller]` attributes.

## Future Work

In the future, we may also want to consider adding additional data to
the task span indicating that the task is spawned on a `JoinSet`...

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-05-16 16:36:24 +00:00
Alice Ryhl 43025631bf Merge 'tokio-util-0.7.x' into master 2022-05-15 10:09:29 +02:00
Alice Ryhl 2a10442389 chore: prepare tokio-util 0.7.2 (#4690) 2022-05-14 21:06:13 +02:00
Alice Ryhl cb1ae462b7 Merge 'tokio-util-0.6.x' into 'tokio-util-0.7.x' 2022-05-14 21:03:16 +02:00
Alice Ryhl 880cf7164a chore: prepare tokio-util 0.6.10 (#4691) 2022-05-14 20:16:41 +02:00
Finomnis dc3aba91e5 sync: rewrite CancellationToken (#4652) 2022-05-14 20:16:36 +02:00
Alice Ryhl 98b03c4698 util: display JoinMap on docs.rs (#4689) 2022-05-14 18:55:26 +02:00
Sabrina Jewson d63ec373a9 util: simplify ReusableBoxFuture (#4675) 2022-05-13 23:39:13 +02:00
Finomnis 4c0d2c233b sync: rewrite CancellationToken (#4652) 2022-05-13 23:26:15 +02:00
Alice Ryhl d51f0b9a23 util: improve impl Send for ReusableBoxFuture docs (#4658) 2022-05-07 22:32:29 +02:00
Erick Tryzelaar 07879f0a5e udp: document and shrink some unsafe blocks (#4655)
This documents why it is safe to convert `bytes::UninitSlice` to `&mut
[MaybeUninit<u8>]`, and shrinks one of the unsafe blocks to make these
functions easier to audit.
2022-05-05 19:48:39 +00:00
Eliza Weisman 019bd9396e util: implement JoinMap (#4640)
## Motivation

In many cases, it is desirable to spawn a set of tasks associated with
keys, with the ability to cancel them by key. As an example use case for
this sort of thing, see Tower's [`ReadyCache` type][1].

Now that PR #4530 adds a way of cancelling tasks in a
`tokio::task::JoinSet`, we can implement a map-like API based on the
same `IdleNotifiedSet` primitive.

## Solution

This PR adds an implementation of a `JoinMap` type to
`tokio_util::task`, using the `JoinSet` type from `tokio::task`, the
`AbortHandle` type added in #4530, and the new task IDs added in #4630.

Individual tasks can be aborted by key using the `JoinMap::abort`
method, and a set of tasks whose key match a given predicate can be
aborted using `JoinMap::abort_matching`.

When tasks complete, `JoinMap::join_one` returns their associated key
alongside the output from the spawned future, or the key and the
`JoinError` if the task did not complete successfully.

Overall, I think the way this works is pretty straightforward; much of
this PR is just API boilerplate to implement the union of applicable
APIs from `JoinSet` and `HashMap`. Unlike previous iterations on the
`JoinMap` API (e.g. #4538), this version is implemented entirely in
`tokio_util`, using only public APIs from the `tokio` crate. Currently,
the required `tokio` APIs are unstable, but implementing `JoinMap` in
`tokio-util` means we will never have to make stability commitments for
the `JoinMap` API itself.

[1]: https://github.com/tower-rs/tower/blob/master/tower/src/ready_cache/cache.rs

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-04-26 17:25:48 +00:00
Paolo Barbolini 8f2a926c64 tracing: don't require default tracing features (#4592) 2022-04-03 11:30:07 +02:00
Dirkjan Ochtman f5d6d0d92f chore: prepare tokio-util 0.7.1 release (#4521) 2022-03-28 14:34:11 +02:00
b-naber fde6b5e746 io: add StreamReader::into_inner_with_chunk (#4559) 2022-03-23 20:41:09 +01:00
Gus Wynn d3da1d770d util: switch tokio-util from log to tracing (#4539) 2022-02-26 12:47:04 +01:00
Nikolai Vazquez f2f3882ae1 codec: add length_field_type to LengthDelimitedCodec builder (#4508) 2022-02-23 11:46:52 +01:00
Takuya Kajiwara b1a210daf8 util: fix import path of CancellationToken in example code (#4520) 2022-02-23 11:46:35 +01:00
b-naber e5b73ea011 util: fix waker update condition in CancellationToken (#4497)
There was a missing exclamation mark in the condition we used to test
whether we need a waker update in `check_for_cancellation`.
2022-02-14 13:18:10 -08:00
Dirkjan Ochtman 7105bdb777 util: bump tokio dependency to 1.6 to satisfy minimal versions (#4490) 2022-02-12 10:02:07 +01:00
Toby Lawrence e4182eb2a3 chore: prepare tokio-util 0.7.0 (#4486) 2022-02-10 12:23:58 -05:00
Kestrer 4a3bc2f261 util: add lifetime parameter to ReusableBoxFuture (#3762)
Co-authored-by: Toby Lawrence <toby@nuclearfurnace.com>
2022-02-09 14:29:21 -05:00
Toby Lawrence d819023aac sync: refactored PollSender<T> to fix a subtly broken Sink<T> implementation (#4214)
Signed-off-by: Toby Lawrence <toby@nuclearfurnace.com>
2022-02-09 12:09:04 -05:00
Benjamin Saunders 32b05eef58 util: remove error case from the infallible DelayQueue::poll_elapsed (#4241) 2022-02-08 21:07:33 -05:00
Sunyeop Lee dcb3391ca7 codec: implement Encoder<BytesMut> for BytesCodec (#4465) 2022-02-08 09:11:24 -05:00
Carl Lerche 3afc6da269 chore: increase MSRV to 1.49. (#4457)
Rust 1.49 was released on December 31, 2020, which meets our MSRV policy
of a minimum of 6 months.
2022-01-31 13:26:12 -08:00
Carl Lerche c46d1c3487 chore: update year in LICENSE files (#4429) 2022-01-27 13:36:21 -08:00
Mark Drobnak 8a567008c2 util: add spawn_pinned (#3370) 2022-01-27 15:26:09 +01:00
Cecile Tonglet 9923e8602e net: add generic trait to combine UnixListener and TcpListener (#4385) 2022-01-27 15:13:37 +01:00
Luiz Carlos 41f911b43d feat: implement Framed::map_codec (#4427) 2022-01-27 12:37:30 +01:00
b-naber fd4558071c util: add shrink_to_fit and compact methods to DelayQueue (#4170) 2022-01-09 12:41:30 +01:00
Tom Dohrmann 1730d3a085 util: add mutable reference getters for codecs to pinned Framed (#4372) 2022-01-03 22:21:43 +01:00
David Kleingeld b0b46052ca codec: improve Builder::max_frame_length docs (#4352) 2021-12-28 15:08:37 +01:00
Toby Lawrence fbdf4bc3b8 chore(util): start v0.7 release cycle (#4313)
* chore(util): start v0.7 release cycle

Signed-off-by: Toby Lawrence <toby@nuclearfurnace.com>
2021-12-10 13:16:17 -05:00
Taiki Endo f81b13146c chore: remove doc URL from Cargo.toml (#4251)
https://doc.rust-lang.org/cargo/reference/manifest.html#the-documentation-field

> If no URL is specified in the manifest file, crates.io will
> automatically link your crate to the corresponding docs.rs page.
2021-11-23 11:53:32 +01:00
Taiki Endo d7ed987b04 ci: upgrade to new nightly (#4268) 2021-11-23 19:29:57 +09:00
Taiki Endo 8c17eb6d64 chore: bump MSRV to 1.46 (#4254) 2021-11-23 12:09:24 +09:00
Alice Ryhl b10a398e63 chore: prepare tokio-util 0.6.9 (#4199) 2021-10-29 18:34:23 +02:00
Bhargav ff3a101de9 codec: update stream impl for Framed to return None after Err (#4166) 2021-10-26 16:56:15 +02:00
Alice Ryhl 49d817ae63 time: update deadline on removal in DelayQueue (#4178) 2021-10-22 20:34:36 +02:00
Colin Walters 3ef7923c67 util/io: add SyncIoBridge (#4146) 2021-10-22 18:46:29 +02:00
Nylonicious 25137023c9 util: update README (#4099) 2021-09-10 08:55:03 +02:00