mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
## Motivation
The `tokio_net` resources can be created outside of a runtime due to how tokio
has been used with futures to date. For example, this allows a `TcpStream` to be
created, and later passed into a runtime:
```
let stream = TcpStream::connect(...).and_then(|socket| {
// do something
});
tokio::run(stream);
```
In order to support this functionality, the reactor was lazily bound to the
resource on the first call to `poll_read_ready`/`poll_write_ready`. This
required a lot of additional complexity in the binding logic to support.
With the tokio 0.2 common case, this is no longer necessary and can be removed.
All resources are expected to be created from within a runtime, and should panic
if not done so.
Closes #1168
## Solution
The `tokio_net` crate now assumes there to be a `CURRENT_REACTOR` set on the
worker thread creating a resource; this can be assumed if called within a tokio
runtime. If there is no current reactor, the application will panic with a "no
current reactor" message.
With this assumption, all the unsafe and atomics have been removed from
`tokio_net::driver::Registration` as it is no longer needed.
There is no longer any reason to pass in handles to the family of `from_std` methods on `net` resources. `Handle::current` has therefore a more restricted private use where it is only used in `driver::Registration::new`.
Signed-off-by: Kevin Leimkuhler <[email protected]>
32 lines
929 B
Rust
32 lines
929 B
Rust
#![cfg(unix)]
|
|
#![cfg(feature = "signal")]
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
pub mod support;
|
|
use support::*;
|
|
|
|
#[test]
|
|
fn dropping_loops_does_not_cause_starvation() {
|
|
let kind = SignalKind::user_defined1();
|
|
|
|
let mut first_rt = CurrentThreadRuntime::new().expect("failed to init first runtime");
|
|
let mut first_signal =
|
|
first_rt.block_on(async { signal(kind).expect("failed to register first signal") });
|
|
|
|
let mut second_rt = CurrentThreadRuntime::new().expect("failed to init second runtime");
|
|
let mut second_signal =
|
|
second_rt.block_on(async { signal(kind).expect("failed to register second signal") });
|
|
|
|
send_signal(libc::SIGUSR1);
|
|
|
|
let _ =
|
|
run_with_timeout(&mut first_rt, first_signal.next()).expect("failed to await first signal");
|
|
|
|
drop(first_rt);
|
|
drop(first_signal);
|
|
|
|
send_signal(libc::SIGUSR1);
|
|
|
|
let _ = run_with_timeout(&mut second_rt, second_signal.next());
|
|
}
|