diff options
author | Kevin Leimkuhler <kleimkuhler@icloud.com> | 2019-10-21 16:20:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-21 16:20:06 -0700 |
commit | c9bcbe77b9fa36868cc94cc75426823c7ec205ac (patch) | |
tree | 796c52bbf53eedf72b9f4dd94370e9387a09f824 /examples/tinydb.rs | |
parent | 978013a215ebae63cd087139514de32bbd36ce11 (diff) |
net: Eagerly bind resources to reactors (#1666)
## 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 <kleimkuhler@icloud.com>
Diffstat (limited to 'examples/tinydb.rs')
0 files changed, 0 insertions, 0 deletions