Feature rollup (#129)

* Create a directory for the `future::server` module, which has become quite large. server.rs => server/mod.rs. Server submodules for shutdown and connection logic are added.

* Add fn thread_pool(...) to sync::server::Options

* Configure idle threads to expire after one minute

* Add tarpc::util::lazy for lazily executing functions. Similar to `futures::lazy` but useful in different circumstances. Specifically, `futures::lazy` typically requires a closure, whereas `util::lazy` kind of deconstructs a closure into its function and args.

* Remove some unstable features, and `cfg(plugin)` only in tests. Features `unboxed_closures` and `fn_traits` are removed by replacing manual Fn impls with Stream impls. This actually leads to slightly more performant code, as well, because some `Rc`s could be removed.

* Fix tokio deprecation warnings. Update to use tokio-io in lieu of deprecated tokio-core items. impl AsyncRead's optional `unsafe fn prepare_uninitialized_buffer` for huge perf wins

* Add debug impls to all public items and add `deny(missing_debug_implementations)` to the crate.

* Bump tokio core version.
This commit is contained in:
Tim
2017-03-31 12:16:40 -07:00
committed by GitHub
parent 15080b2889
commit 5add81b5f3
15 changed files with 1262 additions and 982 deletions

View File

@@ -1,6 +1,8 @@
use bytes::{Buf, BufMut};
use futures::Poll;
use std::io;
use tokio_core::io::Io;
use tokio_core::net::TcpStream;
use tokio_io::{AsyncRead, AsyncWrite};
#[cfg(feature = "tls")]
use tokio_tls::TlsStream;
@@ -52,4 +54,41 @@ impl io::Write for StreamType {
}
}
impl Io for StreamType {}
impl AsyncRead for StreamType {
// By overriding this fn, `StreamType` is obliged to never read the uninitialized buffer.
// Most sane implementations would never have a reason to, and `StreamType` does not, so
// this is safe.
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
match *self {
StreamType::Tcp(ref stream) => stream.prepare_uninitialized_buffer(buf),
#[cfg(feature = "tls")]
StreamType::Tls(ref stream) => stream.prepare_uninitialized_buffer(buf),
}
}
fn read_buf<B: BufMut>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
match *self {
StreamType::Tcp(ref mut stream) => stream.read_buf(buf),
#[cfg(feature = "tls")]
StreamType::Tls(ref mut stream) => stream.read_buf(buf),
}
}
}
impl AsyncWrite for StreamType {
fn shutdown(&mut self) -> Poll<(), io::Error> {
match *self {
StreamType::Tcp(ref mut stream) => stream.shutdown(),
#[cfg(feature = "tls")]
StreamType::Tls(ref mut stream) => stream.shutdown(),
}
}
fn write_buf<B: Buf>(&mut self, buf: &mut B) -> Poll<usize, io::Error> {
match *self {
StreamType::Tcp(ref mut stream) => stream.write_buf(buf),
#[cfg(feature = "tls")]
StreamType::Tls(ref mut stream) => stream.write_buf(buf),
}
}
}