Merge pull request #191 from stjepang/reduce-deps

Reduce the number of dependencies
This commit is contained in:
Stjepan Glavina 2020-07-20 11:33:55 +02:00 committed by GitHub
commit f97ddd9886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 65 additions and 59 deletions

View File

@ -24,47 +24,48 @@ readme = "README.md"
tokio02 = ["tokio"]
[dependencies]
async-io = "0.1.1"
async-io = "0.1.3"
multitask = "0.2.0"
num_cpus = "1.13.0"
once_cell = "1.4.0"
blocking = "0.4.6"
blocking = "0.4.7"
[dependencies.tokio]
version = "0.2"
version = "0.2.21"
default-features = false
features = ["rt-threaded"]
optional = true
[dev-dependencies]
anyhow = "1.0.28"
anyhow = "1.0.31"
async-channel = "1.1.1"
async-dup = "1.1.0"
async-h1 = "1.1.2"
async-dup = "1.2.1"
async-h1 = "2.1.0"
async-native-tls = "0.3.3"
async-std = "1.5.0"
async-tungstenite = { version = "0.4.2", features = ["async-native-tls"] }
base64 = "0.12.0"
ctrlc = "3.1.4"
futures = "0.3.4"
async-std = "1.6.2"
async-tungstenite = { version = "0.7.1", features = ["async-native-tls"] }
base64 = "0.12.3"
ctrlc = "3.1.5"
futures = "0.3.5"
futures-lite = "0.1.5"
http = "0.2.1"
http-types = "1.2.0"
hyper = { version = "0.13.5", default-features = false, features = ["stream"] }
http-types = "2.3.0"
hyper = { version = "0.13.7", default-features = false, features = ["stream"] }
native-tls = "0.2.4"
num_cpus = "1.13.0"
reqwest = "0.10.4"
scraper = "0.11.0"
signal-hook = "0.1.13"
surf = { version = "2.0.0-alpha.1", default-features = false, features = ["h1-client"] }
reqwest = "0.10.6"
scraper = "0.12.0"
signal-hook = "0.1.16"
surf = { version = "2.0.0-alpha.4", default-features = false, features = ["h1-client"] }
tempfile = "3.1.0"
tokio = { version = "0.2", default-features = false }
tungstenite = "0.10.1"
tokio = { version = "0.2.21", default-features = false }
tungstenite = "0.11.0"
url = "2.1.1"
[target.'cfg(target_os = "linux")'.dev-dependencies]
inotify = { version = "0.8.2", default-features = false }
inotify = { version = "0.8.3", default-features = false }
nix = "0.17.0"
timerfd = "1.1.1"
[target.'cfg(windows)'.dev-dependencies]
uds_windows = "0.1.4"
uds_windows = "0.1.5"

View File

@ -11,7 +11,7 @@ use std::net::{TcpStream, ToSocketAddrs};
use anyhow::{bail, Context as _, Error, Result};
use async_io::Async;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures_lite::*;
use http_types::{Method, Request, Response};
use url::Url;

View File

@ -19,7 +19,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor};
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
use http_types::{Request, Response, StatusCode};
use smol::Task;
@ -28,7 +28,7 @@ async fn serve(req: Request) -> http_types::Result<Response> {
println!("Serving {}", req.url());
let mut res = Response::new(StatusCode::Ok);
res.insert_header("Content-Type", "text/plain")?;
res.insert_header("Content-Type", "text/plain");
res.set_body("Hello from async-h1!");
Ok(res)
}
@ -45,14 +45,13 @@ async fn listen(listener: Async<TcpListener>, tls: Option<TlsAcceptor>) -> Resul
loop {
// Accept the next connection.
let (stream, _) = listener.accept().await?;
let host = host.clone();
// Spawn a background task serving this connection.
let task = match &tls {
None => {
let stream = async_dup::Arc::new(stream);
Task::spawn(async move {
if let Err(err) = async_h1::accept(&host, stream, serve).await {
if let Err(err) = async_h1::accept(stream, serve).await {
println!("Connection error: {:#?}", err);
}
})
@ -63,7 +62,7 @@ async fn listen(listener: Async<TcpListener>, tls: Option<TlsAcceptor>) -> Resul
Ok(stream) => {
let stream = async_dup::Arc::new(async_dup::Mutex::new(stream));
Task::spawn(async move {
if let Err(err) = async_h1::accept(&host, stream, serve).await {
if let Err(err) = async_h1::accept(stream, serve).await {
println!("Connection error: {:#?}", err);
}
})

View File

@ -16,8 +16,7 @@ use std::net::TcpStream;
use async_io::Async;
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
fn main() -> io::Result<()> {
block_on(async {
@ -35,10 +34,19 @@ fn main() -> io::Result<()> {
let mut writer = &stream;
// Wait until the standard input is closed or the connection is closed.
futures::select! {
_ = io::copy(stdin, &mut writer).fuse() => println!("Quit!"),
_ = io::copy(reader, &mut stdout).fuse() => println!("Server disconnected!"),
}
future::race(
async {
let res = io::copy(stdin, &mut writer).await;
println!("Quit!");
res
},
async {
let res = io::copy(reader, &mut stdout).await;
println!("Server disconnected!");
res
},
)
.await?;
Ok(())
})

View File

@ -19,8 +19,7 @@ use async_channel::{bounded, Receiver, Sender};
use async_dup::Arc;
use async_io::Async;
use blocking::block_on;
use futures::io::{self, BufReader};
use futures::prelude::*;
use futures_lite::*;
use smol::Task;
/// An event on the chat server.
@ -70,7 +69,7 @@ async fn dispatch(receiver: Receiver<Event>) -> io::Result<()> {
/// Reads messages from the client and forwards them to the dispatcher task.
async fn read_messages(sender: Sender<Event>, client: Arc<Async<TcpStream>>) -> io::Result<()> {
let addr = client.get_ref().peer_addr()?;
let mut lines = BufReader::new(client).lines();
let mut lines = io::BufReader::new(client).lines();
while let Some(line) = lines.next().await {
let line = line?;

View File

@ -7,13 +7,13 @@
//! ```
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
fn main() {
// Set a handler that sends a message through a channel.
let (s, ctrl_c) = async_channel::bounded(100);
let handle = move || {
let _ = s.send(()).now_or_never();
let _ = future::poll_once(s.send(()));
};
ctrlc::set_handler(handle).unwrap();

View File

@ -16,7 +16,7 @@ use anyhow::{bail, Context as _, Error, Result};
use async_io::Async;
use async_native_tls::TlsStream;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures_lite::*;
use http::Uri;
use hyper::{Body, Client, Request, Response};
use smol::Task;
@ -42,7 +42,7 @@ fn main() -> Result<()> {
// Read the message body.
let body = resp
.into_body()
.try_fold(Vec::new(), |mut body, chunk| async move {
.try_fold(Vec::new(), |mut body, chunk| {
body.extend_from_slice(&chunk);
Ok(body)
})
@ -70,7 +70,7 @@ struct SmolConnector;
impl hyper::service::Service<Uri> for SmolConnector {
type Response = SmolStream;
type Error = Error;
type Future = future::BoxFuture<'static, Result<Self::Response, Self::Error>>;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))

View File

@ -23,7 +23,7 @@ use anyhow::{Error, Result};
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use smol::Task;
@ -103,7 +103,7 @@ impl hyper::server::accept::Accept for SmolListener {
cx: &mut Context,
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
let poll = Pin::new(&mut self.listener.incoming()).poll_next(cx);
let stream = futures::ready!(poll).unwrap()?;
let stream = ready!(poll).unwrap()?;
let stream = match &self.tls {
None => SmolStream::Plain(stream),
@ -132,7 +132,7 @@ enum SmolStream {
Tls(TlsStream<Async<TcpStream>>),
/// A TCP connection that is in process of getting secured by TLS.
Handshake(future::BoxFuture<'static, io::Result<TlsStream<Async<TcpStream>>>>),
Handshake(Pin<Box<dyn Future<Output = io::Result<TlsStream<Async<TcpStream>>>> + Send>>),
}
impl hyper::client::connect::Connection for SmolStream {
@ -152,7 +152,7 @@ impl tokio::io::AsyncRead for SmolStream {
SmolStream::Plain(s) => return Pin::new(s).poll_read(cx, buf),
SmolStream::Tls(s) => return Pin::new(s).poll_read(cx, buf),
SmolStream::Handshake(f) => {
let s = futures::ready!(f.as_mut().poll(cx))?;
let s = ready!(f.as_mut().poll(cx))?;
*self = SmolStream::Tls(s);
}
}
@ -171,7 +171,7 @@ impl tokio::io::AsyncWrite for SmolStream {
SmolStream::Plain(s) => return Pin::new(s).poll_write(cx, buf),
SmolStream::Tls(s) => return Pin::new(s).poll_write(cx, buf),
SmolStream::Handshake(f) => {
let s = futures::ready!(f.as_mut().poll(cx))?;
let s = ready!(f.as_mut().poll(cx))?;
*self = SmolStream::Tls(s);
}
}

View File

@ -11,7 +11,7 @@ use std::net::{TcpStream, ToSocketAddrs};
use anyhow::{bail, Context as _, Result};
use async_io::Async;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures_lite::*;
use url::Url;
/// Sends a GET request and fetches the response.

View File

@ -19,7 +19,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor};
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
use smol::Task;
const RESPONSE: &[u8] = br#"

View File

@ -16,8 +16,7 @@ use std::net::TcpStream;
use async_io::Async;
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
fn main() -> io::Result<()> {
block_on(async {

View File

@ -16,7 +16,7 @@ use std::net::{TcpListener, TcpStream};
use async_io::Async;
use blocking::block_on;
use futures::io;
use futures_lite::*;
use smol::Task;
/// Echoes messages from the client back to it.

View File

@ -18,8 +18,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Certificate, TlsConnector};
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
fn main() -> Result<()> {
// Initialize TLS with the local certificate.

View File

@ -18,7 +18,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use blocking::block_on;
use futures::io;
use futures_lite::*;
use smol::Task;
/// Echoes messages from the client back to it.

View File

@ -12,7 +12,7 @@ fn main() -> std::io::Result<()> {
use async_io::Async;
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
block_on(async {
// Create a Unix stream that receives a byte on each signal occurrence.

View File

@ -21,7 +21,8 @@ use async_io::Async;
use async_native_tls::{Certificate, TlsConnector, TlsStream};
use async_tungstenite::WebSocketStream;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures::sink::{Sink, SinkExt};
use futures_lite::*;
use tungstenite::handshake::client::Response;
use tungstenite::Message;
use url::Url;

View File

@ -21,7 +21,8 @@ use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use async_tungstenite::WebSocketStream;
use blocking::block_on;
use futures::prelude::*;
use futures::sink::{Sink, SinkExt};
use futures_lite::*;
use smol::Task;
use tungstenite::Message;

View File

@ -12,8 +12,7 @@ fn main() -> std::io::Result<()> {
use async_io::Async;
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
use smol::Task;
use tempfile::tempdir;
use uds_windows::{UnixListener, UnixStream};