Commit Graph
1749 Commits
Author SHA1 Message Date
Sean McArthur 116a18b849 sync: reduce memory size of watch::Receiver (#2191)
This reduces the `mem::size_of::<watch::Receiver>()` from 4 words to 2.

- The `id` is now the pointer of the `Arc<WatchInner>`.
- The `ver` is moved into the `WatchInner`.
2020-01-29 12:22:21 -08:00
Carl Lerche 9d6b99494b rt: add Runtime::shutdown_timeout (#2186)
Provides an API for forcing a runtime to shutdown even if there are
still running tasks.
2020-01-29 12:00:40 -08:00
Tomasz Miąsko 560d0fa548 rt: read join waker conditionally to avoid data race (#2096)
The previous implementation would perform a load that might be part of a
data race. The value read would be used only when race did not occur.
This would be well defined in a memory model where a load that is a part
of race merely returns an undefined value, the Rust memory model on the
other hand defines it to be undefined behaviour.

Perform read conditionally to avoid data race.

Covered by existing loom tests after changing casualty check to be
immediate rather than deferred.

Fixes: #2087
2020-01-29 11:44:15 -08:00
Carl Lerche 6232c74724 macros: correctly feature gate join/try_join (#2196)
The `macros` feature flag was ommitted despite the fact that these
macros require the feature flag to function. The macros are now scoped
by the `macros` feature flag.

This is *not* a breaking change due to the fact that the macros were
broken without the `macros` feature flag in the first place.
2020-01-29 11:16:58 -08:00
Eliza WeismanandWim Looman be832f20cb util: add futures-io/tokio::io compatibility layer (#2117)
* util: add futures-io/tokio::io compatibility layer

This PR adds a compatibility layer with conversions between the
`tokio::io` and `futures-io` versions of the `AsyncRead` and
`AsyncWrite` traits.

I initially opened this PR against `tokio-compat`, but we decided that
a compatibility layer for current versions of the `tokio` and
`futures-io` crates (rather than for compatibility with legacy code)
ought to go in `tokio-util` instead. See:
https://github.com/tokio-rs/tokio-compat/pull/2#issuecomment-551310953

This is based on code originally written by @Nemo157 as part of the
`futures-tokio-compat` crate, and is contributed on behalf of the
original author:
https://github.com/Nemo157/futures-tokio-compat/issues/2#issuecomment-544118866

Closes tokio-rs/tokio-compat#2

Co-authored-by: Wim Looman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
2020-01-29 11:14:24 -08:00
Avery Harnish 326f724978 chore: fix typos in ROADMAP.md (#2190) 2020-01-29 11:12:35 -08:00
Avery Harnish 81c20d8454 chore: improve discoverability of CoC (#2180) 2020-01-29 10:56:11 -08:00
Jon Gjengset b70f1ce3c0 rt: enable task state assertions under loom (#2192) 2020-01-29 10:50:52 -08:00
Vitor Enes 64e4bd1b2f docs: minor fixes to TcpStream API docs (#2183) 2020-01-28 14:07:51 -08:00
Tore 8ed209b612 docs: fix stream::pending() example (#2189) 2020-01-28 11:07:29 -08:00
Lucio Franco 4a24c7063b sync: add mpsc benchmark (#2166) 2020-01-27 20:48:35 -08:00
Juan Alvarez e2230f3392 timer: fix out of bounds error (#2184) 2020-01-27 20:46:52 -08:00
Carl Lerche 00e3c29e48 chore: prepare v0.2.11 release (#2179)
Also bumps:
- tokio-macros: v0.2.4
tokio-0.2.11 tokio-macros-0.2.4
2020-01-27 10:32:07 -08:00
Carl Lerche bcba4aaa54 docs: write sync mod API docs (#2175)
Fixes #2171
2020-01-27 09:11:12 -08:00
Carl Lerche 71c47fabf4 chore: bump nightly version used in CI (#2178)
This requires fixing a few warnings.
2020-01-26 21:54:14 -08:00
daxpedda 4996e27673 macros: fix skipping generics on #[tokio::main] (#2177)
When using #[tokio::main] on a function with generics, the generics are
skipped. Simply using #vis #sig instead of #vis fn #name(#inputs) #ret
fixes the problem.

Fixes #2176
2020-01-26 09:35:39 -08:00
Carl Lerche 5bf06f2b5a future: provide try_join! macro (#2169)
Provides a `try_join!` macro that supports concurrently driving multiple
`Result` futures on the same task and await the completion of all the
futures as `Ok` or the **first** `Err` future.
2020-01-24 20:26:55 -08:00
Juan Alvarez 12be90e3ff stream: add StreamExt::timeout() (#2149) 2020-01-24 15:22:56 -08:00
Carl Lerche 0d49e112b2 sync: impl equality traits for oneshot::RecvError (#2168) 2020-01-24 15:10:29 -08:00
Avery Harnish 9eca96aa21 rt: improve "no runtime" panic messages (#2145) 2020-01-24 15:10:11 -08:00
Jon Gjengset a16c9a5a01 rt: test block_in_place followed by Pending (#2120) 2020-01-24 15:08:30 -08:00
Dominic f0bfebb7e1 fs: add fs::copy (#2079)
Provides an asynchronous version of `std::fs::copy`.

Closes: #2076
2020-01-24 11:43:26 -08:00
Daniel Fox Franke 968c143acd task: add methods for inspecting JoinErrors (#2051)
Adds `is_cancelled()` and `is_panic()` methods to `JoinError`, as well as
`into_panic()` and `try_into_panic()` methods which, when applicable, returns
the payload of the panic.
2020-01-24 11:23:58 -08:00
wqfish 6fbaac91e0 docs: typo fix in runtime doc (#2167) 2020-01-24 10:56:42 -08:00
David Kellum e35038ed79 rt: add feature flag for using parking_lot internally (#2164)
`parking_lot` provides synchronization primitives that tend to be
more efficient than the ones in `std`. However, depending on
`parking_lot` pulls in a number of dependencies resulting
in additional compilation time.

Adding *optional* support for `parking_lot` allows the end user
to opt-in when the trade offs make sense for their case.
2020-01-24 10:02:19 -08:00
Oleg Nosov f9ddb93604 docs: use third form in API docs (#2027) 2020-01-24 09:31:13 -08:00
Carl Lerche a70f7203a4 macros: add pin! macro (#2163)
Used for stack pinning and based on `pin_mut!` from the pin-util crate.

Pinning is used often when working with stream operators and the select!
macro. Given the small size of `pin!` it makes more sense to include a
version than re-export one from a separate crate or require the user to
depend on `pin-util` themselves.
2020-01-23 14:40:43 -08:00
Carl Lerche 7079bcd609 future: provide join! macro (#2158)
Provides a `join!` macro that supports concurrently driving multiple
futures on the same task and await the completion of all futures.
2020-01-23 13:24:30 -08:00
John-John Tedro f8714e9901 Don't export select unless macros is enabled (#2161) 2020-01-23 18:40:42 +01:00
Artem Vorotnikov 0545b349e1 stream: add StreamExt::fold() (#2122) 2020-01-23 09:03:10 -08:00
Carl Lerche 8cf98d6946 Provide select! macro (#2152)
Provides a `select!` macro for concurrently waiting on multiple async
expressions. The macro has similar goals and syntax as the one provided
by the `futures` crate, but differs significantly in implementation.

First, this implementation does not require special traits to be
implemented on futures or streams (i.e., no `FuseFuture`). A design goal
is to be able to pass a "plain" async fn result into the select! macro.

Even without `FuseFuture`, this `select!` implementation is able to
handle all cases the `futures::select!` macro can handle. It does this
by supporting pre-poll conditions on branches and result pattern
matching. For pre-conditions, each branch is able to include a condition
that disables the branch if it evaluates to false. This allows the user
to guard futures that have already been polled, preventing double
polling. Pattern matching can be used to disable streams that complete.

A second big difference is the macro is implemented almost entirely as a
declarative macro. The biggest advantage to using this strategy is that
the user will not need to alter the rustc recursion limit except in the
most extreme cases.

The resulting future also tends to be smaller in many cases.
2020-01-22 18:59:22 -08:00
kalcutter f9ea576cca sync: fix broadcast bugs (#2135)
Make sure the tail mutex is acquired when `condvar` is notified,
otherwise the wakeup may be lost and the sender could be left waiting.
Use `notify_all()` instead of `notify_one()` to ensure that the correct
sender is woken. Finally, only do any of this when there are no more
readers left.

Additionally, calling `send()` is buggy and may cause a panic when
the slot has another pending send.
2020-01-22 13:59:05 -08:00
Kevin Leimkuhler 7f580071f3 net: add ReadHalf::{poll,poll_peak} (#2151)
The `&mut self` requirements for `TcpStream` methods ensure that there are at
most two tasks using the stream--one for reading and one for writing.

`TcpStream::split` allows two separate tasks to hold a reference to a single
`TcpStream`. `TcpStream::{peek,poll_peek}` only poll for read readiness, and
therefore are safe to use with a `ReadHalf`.

Instead of duplicating `TcpStream::poll_peek`, a private method is now used by
both `poll_peek` methods that uses the fact that only a `&TcpStream` is
required.

Closes #2136
2020-01-22 13:22:10 -08:00
Przemysław Bitkowski 5fe2df0fba docs: fix link to website (#2103)
replace website link, because previous one was broken
2020-01-22 11:06:26 -08:00
Carl Lerche 176df2448a macros: remove unused attributes (#2147) 2020-01-22 10:31:48 -08:00
gliderkite 5bbf976268 Enhance documentation of tokio::task::block_in_place (#2155) 2020-01-22 11:34:09 -05:00
David Barsky 90969420a2 docs: fix incorrectly rendered doc tests; tighten phrasing (#2150) 2020-01-21 21:58:20 -05:00
Carl Lerche bffbaab30d chore: prepare v0.2.10 release (#2148) tokio-0.2.10 2020-01-21 13:33:02 -08:00
Koki Kato a5e774bb38 sync: derive PartialEq for error enums (#2137) 2020-01-21 11:25:44 -08:00
Lucio Franco 0bb17300f7 sync: add std error impl for broadcast errors (#2141) 2020-01-21 11:25:05 -08:00
Lucio Franco c7719a2d29 io: simplify split check (#2144)
* io: Clean up split check

* fix tests
2020-01-21 11:19:36 -08:00
Carl Lerche 38bff0adda macros: fix #[tokio::main] without rt-core (#2139)
The Tokio runtime provides a "shell" runtime when `rt-core` is not
available. This shell runtime is enough to support `#[tokio::main`] and
`#[tokio::test].

A previous change disabled these two attr macros when `rt-core` was not
selected. This patch fixes this by re-enabling the `main` and `test`
attr macros without `rt-core` and adds some integration tests to prevent
future regressions.
2020-01-21 10:46:32 -08:00
Markus Westerlind fbe143b142 fix: Prevent undefined behaviour from malicious AsyncRead impl (#2030)
`AsyncRead` is safe to implement but can be implemented so that it
reports that it read more bytes than it actually did. `poll_read_buf` on
the other head implicitly trusts that the returned length is actually
correct which makes it possible to advance the buffer past what has
actually been initialized.

An alternative fix could be to avoid the panic and instead advance by
`n.min(b.len())`
2020-01-21 10:35:13 -08:00
Carl Lerche 9df805ff54 chore: do not depend on loom on windows (#2146)
Loom currently does not compile on windows due to a
transitive dependency on `generator`. The `generator`
crate builds have started to fail on windows CI. Loom
is not run under windows, however, so removing the
loom dependency on windows is sufficient to fix CI.

Refs: https://github.com/Xudong-Huang/generator-rs/issues/19
2020-01-21 10:15:54 -08:00
Lucio Franco 5d82ac2d1e readme: Add more related tokio projects (#2128) 2020-01-21 10:00:18 -05:00
Maarten de Vries 5bf78d77ad Add a method to test if split streams come from the same stream. (#1762)
* Add a method to test if split streams come from the same stream.

The exposed stream ID can also be used as key in associative containers.

* Document the fact that split stream IDs can dangle.
2020-01-20 19:50:31 -05:00
Vitor Enes 3176d0a48a io: add BufStream::with_capacity (#2125) 2020-01-20 19:27:34 -05:00
David Kellum bb6c3839ef Yield now docs (#2129)
* add subsections for the blocking and yielding examples in task mod

* flesh out yield_now rustdoc

* add a must_use for yield_now
2020-01-20 16:51:47 -05:00
Pierre Krieger 1475448bdf runtime: add Handle::try_current (#2118)
* runtime: add Handle::try_current

Makes it possible to get a Handle only if a Runtime has been started, without panicing if that isn't the case

* Use an error instead
2020-01-20 11:09:52 -05:00
Pen Tree 7eb8d447ad tokio-tls: rename echo.rs to tls-echo.rs (#2133) 2020-01-19 15:53:28 -05:00