Commit Graph
497 Commits
Author SHA1 Message Date
Carl Lerche 2eabc37599 I/O resources lazily bind to reactor. (#160)
This patch makes a significant change to how I/O resources bind to a
reactor. Currently, an I/O resource (TCP, UDP, PollEvented) will bind
itself with a reactor upon creation.

First, some history.

Originally, tokio-core required that I/O resources be explicitly
associated with a reactor upon creation by passing in a `&Handle`. Tokio
reform introduced a default reactor. If I/O resources do not specify a
reactor upon creation, then the default reactor is used.

However, futures tend to favor being lazy. Creating a future should do
no work, instead it is defining a computation to be performed once the
future is executed. Binding an I/O resource with a reactor on creation
goes against this pattern.

This patch fixes this by allowing I/O resources to lazily bind to a
reactor. An explicit `&Handle` can still be used on creation, but if no
reactor is specified, then the default reactor is used. However, this
binding happens during execution time (read / write) and not creation.
2018-02-28 09:03:13 -08:00
Roman 1190176be7 Improve current thread tests (#161)
* Create variables as closer as possible to their usage
* Check that no message is lost in test current_thread::hammer_turn
2018-02-28 09:00:25 -08:00
Carl Lerche 8e1a9101f0 Support current_thread::spawn from task drop (#157)
Currently, the thread-local tracking the current thread executor is not
set when a task is dropped. This means that one cannot spawn a new
future from within the drop implementation of another future.

This patch adds support for this by setting the thread-local before
releasing a task.

This implementation is a bit messy. It probably could be cleaned up, but
this is being put off in favor of trying a more comprehensive
reorganization once the current thread executor is feature complete.
2018-02-27 09:56:29 -08:00
Roman 427b7325d0 Update badges in README (#159) 2018-02-27 09:35:50 -08:00
Carl Lerche 2961a2388c Fix race condition in CurrentThread. (#156)
The logic that enables `CurrentThread::turn` to avoid unbounded
iteration was incorrect. It was possible for unfortunate timing to
result in a dead lock.

This patch provides a fix as well as a test.
2018-02-26 20:41:06 -08:00
Carl Lerche df3a92532b Only deploy docs on linux. Take 2 (#155)
Try using an env var to enforce the doc deploy condition.
2018-02-26 14:50:07 -08:00
Carl Lerche 23f451e8b1 Only deploy docs on linux (#154) 2018-02-26 14:12:41 -08:00
Ben Boeckel 40cbd0f296 length_delimited: add a native_endian builder method (#144)
This method is useful when reading from a operating system service.
2018-02-26 10:38:56 -08:00
Alan Somers 3b64fe9363 Lio3 (#142)
FreeBSD uses a separate kqueue filter type for lio_listio.  This change
adds support for that filter type.  Full functionality will be provided
by the mio-aio and tokio-file crates.

* Add PollEvented::into_inner

Consumes a PollEvented and returns its inner io object.  Useful for io
types that have exclusive ownership of a resource.

See also https://github.com/tokio-rs/tokio-core/commit/9400ffb
2018-02-26 09:39:57 -08:00
Carl Lerche 5334de5e44 Fix bug with CurrentThread::turn (#152)
CurrentThread::turn uses a turn count strategy to allow `turn` to not
run infinitely. Currently, there is a bug where spawned tasks will not
get executed in calls to `turn`.

This patch fixes the bug by correctly setting the turn count for newly
spawned tasks.
2018-02-23 22:15:46 -08:00
Carl Lerche fe14e7b127 Introduce the Tokio runtime: Reactor + Threadpool (#141)
This patch is an intial implementation of the Tokio runtime. The Tokio
runtime provides an out of the box configuration for running I/O heavy
asynchronous applications.

As of now, the Tokio runtime is a combination of a work-stealing thread
pool as well as a background reactor to drive I/O resources.

This patch also includes tokio-executor, a hopefully short lived crate
that is based on the futures 0.2 executor RFC.

* Implement `Park` for `Reactor`

This enables the reactor to be used as the thread parker for executors.
This also adds an `Error` component to `Park`. With this change, a
`Reactor` and a `CurrentThread` can be combined to achieve the
capabilities of tokio-core.
2018-02-21 07:42:22 -08:00
Carl Lerche e0d95aa037 Update root license file 2018-02-20 15:13:52 -08:00
cetra3 dc225faf24 Adjust handle documentation (#140) 2018-02-14 14:23:39 -08:00
Roman 8605d5d243 Make benches compilable again (#133) 2018-02-13 10:02:06 -08:00
Carl Lerche 4704f61277 Remove references to Remote (#135)
Fixes #121
2018-02-12 14:13:11 -08:00
Roman 88a7030f73 Split io code (#129)
* move src/io.rs -> src/io/mod.rs
* move src/read.rs -> src/io/read.rs
* move src/read_exact.rs -> src/io/read_exact.rs
* move src/read_until.rs -> src/io/read_until.rs
* move src/read_to_end.rs -> src/io/read_to_end.rs
* move src/flush.rs -> src/io/flush.rs
* move src/copy.rs -> src/io/copy.rs
* move src/shutdown.rs -> src/io/shutdown.rs
* move src/write_all.rs -> src/io/write_all.rs
* move Async{Read,Write} => src/io/async_{read,write}.rs
* move Async{Read,Write} => src/async_{read,write}.rs
2018-02-12 09:52:05 -08:00
Roman 35aeabd3ff Split codec code (#128)
* move src/codec.rs -> src/codec/mod.rs
* Move traits Encoder and Decoder from src/framed_{read|write}.rs into src/codec/{encoder,decoder}.rs
* Move LinesCodec and BytesCodec from src/codecs.rs into src/codec/{lines,bytes}_codec.rs
2018-02-12 09:10:19 -08:00
Carl Lerche 0b58bded7c Bump version to v0.1.1 (#131) tokio-0.1.1 2018-02-09 14:30:32 -08:00
Carl Lerche 609786ed41 Remove fn that was never intended to be pub (#130)
This function could not be called from a public setting in the first
place due to the argument types being private.
2018-02-09 11:32:38 -08:00
Carl Lerche a9da59882c Fix example doc comment (#124)
Fixes #123
2018-02-08 09:09:02 -08:00
Carl Lerche 4ae76132c1 Update the required Mio point release. (#120)
Tokio depends on the latest Mio point release, so update Cargo.toml to
reflect this.
2018-02-07 14:45:12 -08:00
Carl Lerche 23bc9d20d3 Prepare for tokio 0.1 release (#119) tokio-0.1.0 tokio-io-0.1.5 2018-02-07 13:28:29 -08:00
Carl Lerche c225b46b18 Make Handle::wakeup private (#117)
The `Handle` type is intended to be used by end users of Tokio. The
wakeup functionlity is needed by executor implementations. It doesn't
make sense to put executor specific functionality on a type that is
intended for end users.
2018-02-07 11:09:44 -08:00
Carl Lerche c30fa62dda Remove framed fn from UdpSocket (#116)
Instead, use `UdpFramed::new` to create a framed wrapper around the UDP
socket.
2018-02-07 10:42:27 -08:00
Roman ad8338e4da Remove UdpCodec (#109)
`UdpFramed` is updated to use the `Encoder` and
`Decoder` traits from `tokio-io`.
2018-02-06 13:41:31 -08:00
cssivision 73b763f69f Fix: struct shoutdown ignore Async::NotReady (#114) 2018-02-06 13:30:05 -08:00
Carl Lerche f0ea9d6f4c Switch back to futures from crates.io (#113)
Doing so requires copying the `current_thread` executor from GitHub into
the repo.
2018-02-06 07:26:21 -08:00
Carl Lerche 567887cc75 Add a chat example (#112) 2018-02-05 20:45:12 -08:00
Roman 3840ceafee Rename TcpStreamNew -> ConnectFuture (#111) 2018-02-05 20:09:00 -08:00
Carl Lerche a5e9c311bf Fix link to documentation in README (#108) 2018-02-02 13:46:15 -08:00
Carl Lerche 2e94b658ed Track futures tokio-reform branch (#88)
This patch also updates tests and examples to remove deprecated API
usage.
2018-02-01 10:31:07 -08:00
Carl Lerche b9db119b45 Move tokio-io into the git repository. (#96)
The crates remain separate, but are now developed in the same git
repository using cargo workspaces.

This facilitates making coordinated changes.
2018-01-31 21:06:42 -08:00
Carl Lerche a87936080b Limit the max number of registered resources (#95)
* Limit the max number of registered resources

This allows some token space to be used internally. Also, Mio 0.7 will
be limiting the token space some as well.

Mio: https://github.com/carllerche/mio/issues/788

Closes #42
2018-01-31 20:09:44 -08:00
Carl Lerche 65cbfced29 Poll evented mutability (#37)
Generally speaking, it is unsafe to access to perform asynchronous
operations using `&self`. Taking `&self` allows usage from a `Sync`
context, which has unexpected results.

Taking `&mut self` to perform these operations prevents using these
asynchronous values from across tasks (unless they are wrapped in
`RefCell` or `Mutex`.
2018-01-31 20:09:15 -08:00
Carl Lerche a616220090 Move set_fallback to Reactor from Handle. (#93)
The caller should be required to have control of a reactor when setting
it as a fallback. A `Handle` is used to pass into libraries and
functions and should not grant capability of using the associated
reactor as a fallback.

Closes #71
2018-01-31 12:39:47 -08:00
Carl Lerche a998367002 Add CHANGELOG stub. 2018-01-30 13:27:12 -08:00
Carl Lerche c1c06f8ac1 Remove UDP only_v6 accessors. (#94)
These fns are not included on std's UdpSocket.
2018-01-30 15:26:02 -06:00
Carl Lerche ae627db266 Change net::Incoming signature to match std. (#89)
std's `Incoming` iterator yields `TcpStream` instances. This patch
updates the `Incoming` future to match this signature.

This changes the yielded value from `(TcpStream, SocketAddr)` ->
`TcpStream`.
2018-01-30 15:01:34 -06:00
Carl Lerche f4ec9a6360 Remove only_v6 from TCP types (#90) 2018-01-30 14:59:23 -06:00
Carl Lerche 0f4706d752 Update send_dgram function signature. (#91)
* Update send_dgram function signature.

All other fns take `&SocketAddr`.

* Fix tests
2018-01-30 14:49:55 -06:00
Carl Lerche 117dcba8cb Remove &addr arg from TcpListener::from_std (#92)
This has been deprecated in mio.
2018-01-30 14:49:32 -06:00
Carl Lerche fd37fb0f17 Merge remote-tracking branch 'core/master' into new-crate 2018-01-26 14:50:41 -08:00
Carl Lerche a41c0800f9 Uncomment deny(warnings) 2018-01-26 10:12:19 -08:00
Sean McArthur e140dabed2 Use 64 iovecs in TcpStream::write_buf (#295) 2018-01-26 09:17:44 -08:00
Alex Crichton fbdf04f604 More OSX fixes 2018-01-25 07:32:55 -08:00
Alex Crichton a3c4aec127 Fix compile on OSX 2018-01-22 08:14:05 -08:00
Alex Crichton 730228c8cb Add debug logs for how long dispatch takes (#81)
I've often found this to be quite useful when debugging why event loops are
stuck or some other bug looks to be in play.
2018-01-18 13:00:53 -06:00
Alex Crichton 826e27685c Delete the IoToken type (#83)
This was added oh-so-long ago and nowadays is just used by one consumer,
`PollEvented`. Let's just inline the already small implementation directly into
`PollEvented` which should make it easier to modify in the future as well
2018-01-18 10:48:59 -08:00
Roman 025f52aadc Fix UdpCodec::encode (#85)
*     Refactor UDP SendDgram & RecvDgram

    Get rid of unnamed structs in the favor of private structs with named fields

*     Change the signature of UdpCodec::encode

    Now it is:

    ```
        fn encode(&mut self, msg: Self::Out, buf: &mut Vec<u8>) -> Result<SocketAddr, Self::Error>;
    ```

    Closes https://github.com/tokio-rs/tokio/issues/79

* Fix compilation error from `mio` crate
2018-01-16 08:49:59 -08:00
Michal 'vorner' Vaner b081e9593f Get rid of some deprecated warnings (#292)
And allow the others to pass.
2018-01-13 12:03:30 -06:00