Commit Graph
315 Commits
Author SHA1 Message Date
Carl Lerche bf1305c421 Bump version to v0.1.3 (#213) 2018-03-09 11:41:31 -08:00
Carl Lerche cf7435ba30 CurrentThread::turn should block on idle. (#212)
This patch fixes a bug where `CurrentThread::turn` is expected to block
even if the executor is idle.

The `turn` API is the low level interface for callers to interact with
the `Sleep` instance used by the `CurrentThread` instance. As such, a
call to `turn` is expected to call `sleep` once if the executor did not
perform any work.
2018-03-09 11:09:10 -08:00
Carl Lerche e18c23afa1 Bump tokio to v0.1.2 (#201)
This also bumps tokio-io to v0.1.6 and prepares for the initial release
of tokio-executor, tokio-reactor, and tokio-threadpool.
2018-03-08 20:15:51 -08:00
Carl Lerche bb9de276ae Add an explicit spawn fn to TaskExecutor (#200) 2018-03-08 14:54:31 -08:00
Jake Goulding 7da5603a42 Remove premature French translation of "current" (#197) 2018-03-08 08:48:46 -08:00
Carl Lerche 25dd54d263 Improve poll_read_ready implementation (#193)
This patch updates `poll_read_ready` to take a `mask` argument, enabling
the caller to specify the desired readiness. `need_read` is renamed to
`clear_read_ready` and also takes a mask.

This enables a caller to listen for HUP events without requiring reading
from the I/O resource.
2018-03-07 16:24:51 -08:00
Carl Lerche c769b915b7 Explicitly deregister I/O resources on drop (#189)
Mio will be requiring `deregister` to be called explicitly in order to
guarantee that Poll releases any state associated with the I/O resource.
See carllerche/mio#753.

This patch adds an explicit `deregister` function to `Registration` and
updates `PollEvented` to call this function on drop.

`Registration::deregister` is also called on `PollEvented::into_inner`.

Closes #168
2018-03-06 14:40:20 -08:00
Roman 56c5797872 Split net::udp code into files: (#183)
- UdpSocket -> src/net/udp/socket.rs
- SendDgram -> src/net/udp/send_dgram.rs
- RecvDgram -> src/net/udp/recv_dgram.rs
2018-03-06 09:53:23 -08:00
Roman 687871d3e5 Split net::tcp code into files: (#177)
- Incoming -> src/net/tcp/incoming.rs
- TcpListener -> src/net/tcp/listener.rs
- TcpStream, ConnectFuture -> src/net/tcp/stream.rs
2018-03-05 12:44:09 -08:00
Carl Lerche 9f7a98af3c Switch TCP/UDP fns to poll_ -> Poll<...> style (#175)
Tokio is moving away from using `WouldBlock`, instead favoring
`Async::NotReady`.

This patch updates the TCP and UDP types, deprecating any function that
returns `WouldBlock` and adding a poll_ prefixed equivalent.
2018-03-04 10:46:54 -08:00
Carl Lerche 7db7719419 Tweak the tokio::spawn function (#171)
Currently, `tokio::spawn` matched the `spawn` function from futures 0.2.
However, this adds additional ergonomic overhead and removes the ability
to spawn from a drop fn. See rust-lang-nursery/futures-rs#830.

This patch switches the behavior to access the thread-local variable
referencing the default executor directly in the `spawn` function.
2018-03-02 15:45:35 -08:00
Carl Lerche e1b3085153 Extract the reactor to a dedicated crate. (#169)
This allows libraries that require access to reactor related types to
depend on this crate without having to depend on the entirety of Tokio.

For example, libraries that implement their custom I/O resource will
need to access `Registration` or `PollEvented`.
2018-03-02 13:51:34 -08:00
Carl Lerche df19119c0a Add io facade and update reactor docs (#166)
This patch updates the documentation for a number of APIs. It also
introduces a prelude module and an io facade module, re-exporting types
from tokio-io.
2018-03-01 21:48:18 -08:00
Carl Lerche 7de749b77b Provide a handle to Runtime's executor. (#162)
Sometimes, passing ownership to an executor is necessary. For example,
some libraries require taking ownership of one.

This patch adds a function that returns an executor associated with a
runtime.
2018-02-28 09:07:14 -08:00
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
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
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
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
cetra3 dc225faf24 Adjust handle documentation (#140) 2018-02-14 14:23:39 -08:00
Carl Lerche 4704f61277 Remove references to Remote (#135)
Fixes #121
2018-02-12 14:13:11 -08:00
Carl Lerche 0b58bded7c Bump version to v0.1.1 (#131) 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 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
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
Roman 3840ceafee Rename TcpStreamNew -> ConnectFuture (#111) 2018-02-05 20:09:00 -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
Sean McArthur ce014943ec add TcpStream::peek (#291) 2018-01-08 11:34:33 -06:00
Alex Crichton dac13c1df4 Use an events iterator rather than indexing (#82)
Eventually mio won't provide an indexable interface, so switch over to using the
iterator-based interface for now.
2018-01-05 08:47:01 -08:00
Alex Crichton cde387d7e7 Touch up documentation for Reactor::turn 2017-12-19 14:18:28 -08:00