feat(lib): update Tokio, bytes, http, h2, and http-body

This commit is contained in:
Sean McArthur
2019-12-03 14:36:20 -08:00
parent 131962c86a
commit cb3f39c2dc
51 changed files with 985 additions and 1305 deletions

View File

@@ -12,13 +12,11 @@ use std::error::Error as StdError;
use std::fmt;
use std::mem;
#[cfg(feature = "tcp")] use std::net::SocketAddr;
#[cfg(feature = "tcp")] use std::time::Duration;
use bytes::Bytes;
use futures_core::Stream;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite};
use pin_project::{pin_project, project};
#[cfg(feature = "tcp")] use tokio_net::driver::Handle;
use crate::body::{Body, Payload};
use crate::common::exec::{Exec, H2Exec, NewSvcExec};
@@ -357,7 +355,7 @@ impl<E> Http<E> {
/// # use hyper::{Body, Request, Response};
/// # use hyper::service::Service;
/// # use hyper::server::conn::Http;
/// # use tokio_io::{AsyncRead, AsyncWrite};
/// # use tokio::io::{AsyncRead, AsyncWrite};
/// # async fn run<I, S>(some_io: I, some_service: S)
/// # where
/// # I: AsyncRead + AsyncWrite + Unpin + Send + 'static,
@@ -419,74 +417,6 @@ impl<E> Http<E> {
}
}
#[cfg(feature = "tcp")]
#[doc(hidden)]
#[deprecated]
#[allow(deprecated)]
pub fn serve_addr<S, Bd>(&self, addr: &SocketAddr, make_service: S) -> crate::Result<Serve<AddrIncoming, S, E>>
where
S: MakeServiceRef<
AddrStream,
Body,
ResBody=Bd,
>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
S::Service: HttpService<Body>,
Bd: Payload,
E: H2Exec<<S::Service as HttpService<Body>>::Future, Bd>,
{
let mut incoming = AddrIncoming::new(addr, None)?;
if self.keep_alive {
incoming.set_keepalive(Some(Duration::from_secs(90)));
}
Ok(self.serve_incoming(incoming, make_service))
}
#[cfg(feature = "tcp")]
#[doc(hidden)]
#[deprecated]
#[allow(deprecated)]
pub fn serve_addr_handle<S, Bd>(&self, addr: &SocketAddr, handle: &Handle, make_service: S) -> crate::Result<Serve<AddrIncoming, S, E>>
where
S: MakeServiceRef<
AddrStream,
Body,
ResBody=Bd,
>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
Bd: Payload,
E: H2Exec<<S::Service as HttpService<Body>>::Future, Bd>,
{
let mut incoming = AddrIncoming::new(addr, Some(handle))?;
if self.keep_alive {
incoming.set_keepalive(Some(Duration::from_secs(90)));
}
Ok(self.serve_incoming(incoming, make_service))
}
#[doc(hidden)]
#[deprecated]
pub fn serve_incoming<I, IO, IE, S, Bd>(&self, incoming: I, make_service: S) -> Serve<I, S, E>
where
I: Accept<Conn=IO, Error=IE>,
IE: Into<Box<dyn StdError + Send + Sync>>,
IO: AsyncRead + AsyncWrite + Unpin,
S: MakeServiceRef<
IO,
Body,
ResBody=Bd,
>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
Bd: Payload,
E: H2Exec<<S::Service as HttpService<Body>>::Future, Bd>,
{
Serve {
incoming,
make_service,
protocol: self.clone(),
}
}
pub(super) fn serve<I, IO, IE, S, Bd>(&self, incoming: I, make_service: S) -> Serve<I, S, E>
where
I: Accept<Conn=IO, Error=IE>,
@@ -843,7 +773,7 @@ where
loop {
if let Some(connecting) = ready!(me.serve.as_mut().poll_next_(cx)?) {
let fut = NewSvcTask::new(connecting, watcher.clone());
me.serve.as_mut().project().protocol.exec.execute_new_svc(fut)?;
me.serve.as_mut().project().protocol.exec.execute_new_svc(fut);
} else {
return Poll::Ready(Ok(()));
}
@@ -876,7 +806,7 @@ where
pub(crate) mod spawn_all {
use std::error::Error as StdError;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite};
use crate::body::{Body, Payload};
use crate::common::exec::H2Exec;

View File

@@ -59,7 +59,7 @@ use std::fmt;
#[cfg(feature = "tcp")] use std::time::Duration;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite};
use pin_project::pin_project;
use crate::body::{Body, Payload};
@@ -113,7 +113,7 @@ impl Server<AddrIncoming, ()> {
/// This method will panic if binding to the address fails. For a method
/// to bind to an address and return a `Result`, see `Server::try_bind`.
pub fn bind(addr: &SocketAddr) -> Builder<AddrIncoming> {
let incoming = AddrIncoming::new(addr, None)
let incoming = AddrIncoming::new(addr)
.unwrap_or_else(|e| {
panic!("error binding to {}: {}", addr, e);
});
@@ -122,14 +122,13 @@ impl Server<AddrIncoming, ()> {
/// Tries to bind to the provided address, and returns a [`Builder`](Builder).
pub fn try_bind(addr: &SocketAddr) -> crate::Result<Builder<AddrIncoming>> {
AddrIncoming::new(addr, None)
AddrIncoming::new(addr)
.map(Server::builder)
}
/// Create a new instance from a `std::net::TcpListener` instance.
pub fn from_tcp(listener: StdTcpListener) -> Result<Builder<AddrIncoming>, crate::Error> {
let handle = tokio_net::driver::Handle::default();
AddrIncoming::from_std(listener, &handle)
AddrIncoming::from_std(listener)
.map(Server::builder)
}
}

View File

@@ -1,6 +1,6 @@
use std::error::Error as StdError;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite};
use pin_project::{pin_project, project};
use crate::body::{Body, Payload};

View File

@@ -4,9 +4,8 @@ use std::net::{SocketAddr, TcpListener as StdTcpListener};
use std::time::Duration;
use futures_util::FutureExt as _;
use tokio_net::driver::Handle;
use tokio_net::tcp::TcpListener;
use tokio_timer::Delay;
use tokio::net::TcpListener;
use tokio::time::Delay;
use crate::common::{Future, Pin, Poll, task};
@@ -25,20 +24,15 @@ pub struct AddrIncoming {
}
impl AddrIncoming {
pub(super) fn new(addr: &SocketAddr, handle: Option<&Handle>) -> crate::Result<Self> {
pub(super) fn new(addr: &SocketAddr) -> crate::Result<Self> {
let std_listener = StdTcpListener::bind(addr)
.map_err(crate::Error::new_listen)?;
if let Some(handle) = handle {
AddrIncoming::from_std(std_listener, handle)
} else {
let handle = Handle::default();
AddrIncoming::from_std(std_listener, &handle)
}
AddrIncoming::from_std(std_listener)
}
pub(super) fn from_std(std_listener: StdTcpListener, handle: &Handle) -> crate::Result<Self> {
let listener = TcpListener::from_std(std_listener, &handle)
pub(super) fn from_std(std_listener: StdTcpListener) -> crate::Result<Self> {
let listener = TcpListener::from_std(std_listener)
.map_err(crate::Error::new_listen)?;
let addr = listener.local_addr().map_err(crate::Error::new_listen)?;
Ok(AddrIncoming {
@@ -53,7 +47,7 @@ impl AddrIncoming {
/// Creates a new `AddrIncoming` binding to provided socket address.
pub fn bind(addr: &SocketAddr) -> crate::Result<Self> {
AddrIncoming::new(addr, None)
AddrIncoming::new(addr)
}
/// Get the local address bound to this listener.
@@ -135,7 +129,7 @@ impl AddrIncoming {
error!("accept error: {}", e);
// Sleep 1s.
let mut timeout = tokio_timer::delay_for(Duration::from_secs(1));
let mut timeout = tokio::time::delay_for(Duration::from_secs(1));
match Pin::new(&mut timeout).poll(cx) {
Poll::Ready(()) => {
@@ -197,8 +191,8 @@ mod addr_stream {
use std::io;
use std::net::SocketAddr;
use bytes::{Buf, BufMut};
use tokio_net::tcp::TcpStream;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio::net::TcpStream;
use tokio::io::{AsyncRead, AsyncWrite};
use crate::common::{Pin, Poll, task};
@@ -232,8 +226,7 @@ mod addr_stream {
}
impl AsyncRead for AddrStream {
#[inline]
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [u8]) -> bool {
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
self.inner.prepare_uninitialized_buffer(buf)
}