Commit Graph
330 Commits
Author SHA1 Message Date
Stefan Bühler 6defeeb2ba current_thread: make underlying Park instance accessible 2018-05-01 14:33:38 -07:00
Sebastian Dröge 6ea00162b9 Make CurrentThread::turn() more fair by always parking with 0 timeout… (#313)
This ensures that all fd-based futures are put into the queue for the
current tick, if the CurrentThread is parking via the Reactor.

Otherwise, if there are queued up futures already, only those would be
polled in the turn. These futures could then notify others/themselves to
have the queue still non-empty on the next turn. Which then potentially
allows the reactor to never be polled, and thus fd-based futures are
never queued up and polled.

Also return in the Turn return value whether any futures were polled at
all, which allows the caller to know if any work was done at all in this
turn and based on that adjust behavior.
2018-04-25 10:37:18 -07:00
Leandro Pacheco a6b307cfbe re-export io::{ReadHalf/WriteHalf} timer::Error (#290) 2018-04-04 09:18:12 -07:00
Carl Lerche 10cb9dd468 Actually bump tokio to v0.1.5 (#273) 2018-03-30 15:37:52 -07:00
Carl Lerche ea172537aa Rename Sleep to Delay (#270)
This patch renames `Sleep` from tokio-timer and the tokio facade to
`Delay`. Given that the future does not actually put anything to sleep,
the `Delay` name feels more appropriate.

Fixes #263
2018-03-30 14:21:48 -07:00
Carl Lerche baa2502ec6 Integrate timers with runtime. (#266)
This patch integrate the new timer implementation with the runtime by
initializing a timer per worker thread. This allows minimizing the
amount of synchronization needed for using timers.
2018-03-30 11:50:02 -07:00
Carl Lerche 9cffda59c9 Bump version to v0.1.4 (#252)
This also bumps:

* tokio-executor: v0.1.1
* tokio-reactor: v0.1.1
* tokio-threadpool: v0.1.1
2018-03-23 10:34:42 -07:00
Roman 494f0dc176 Runtime builder (#234)
* Split runtime module into files
* Add runtime::Builder to set up thread pool.
2018-03-21 11:23:36 -07:00
Aaron Turon 7b1306e6c2 Add top-level tests for futures 0.2 integration (#231) 2018-03-15 16:38:12 -07:00
Sean McArthur b7f4e337be set Runtime thread pool name prefix (#232) 2018-03-15 16:37:32 -07:00
Sam Rijs 923a80e098 Move tokio::net module into tokio tcp/udp crates (#224) 2018-03-14 09:38:59 -07:00
Aaron Turon d304791c0e Simultaneous futures compat (#172)
This patch adds opt-in support for futures 0.2.
2018-03-13 13:57:35 -07:00
Carl Lerche 8eb3e58b7d Shutdown the runtime on drop (#214)
Currently, the runtime does not shutdown if the runtime handle is
dropped. This can happen during a panic or when the value is simply
dropped.

This patch forces the runtime to shutdown if it is not explicitly
shutdown.

Fixes #209
2018-03-13 13:14:51 -07:00
hcpl 5dab821b29 Fix docs markup (#225) 2018-03-13 11:43:05 -07:00
Wesley Moore 2abeff01a5 Fix build on FreeBSD (#218) 2018-03-13 11:24:17 -07:00
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