Skip to content

Commit e6953ac

Browse files
authored
Merge pull request #201 from forkgull/no-async-std
Replace async-std with smol crates
2 parents 882fa23 + 235de5b commit e6953ac

13 files changed

+48
-36
lines changed

Cargo.toml

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ readme = "README.md"
1818
edition = "2018"
1919

2020
[dependencies]
21-
httparse = "1.3.4"
22-
async-std = "1.7.0"
21+
async-channel = "1.5.1"
22+
async-dup = "1.2.2"
23+
async-global-executor = "2.3.1"
24+
async-io = "1.13.0"
25+
futures-lite = "1.13.0"
2326
http-types = { version = "2.9.0", default-features = false }
24-
futures-core = "0.3.8"
27+
httparse = "1.3.4"
2528
log = "0.4.11"
2629
pin-project = "1.0.2"
27-
async-channel = "1.5.1"
28-
async-dup = "1.2.2"
2930

3031
[dev-dependencies]
31-
pretty_assertions = "0.6.1"
3232
async-std = { version = "1.7.0", features = ["attributes"] }
33+
pretty_assertions = "0.6.1"

src/body_encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io;
22
use std::pin::Pin;
33
use std::task::{Context, Poll};
44

5-
use async_std::io::Read;
5+
use futures_lite::io::AsyncRead as Read;
66
use http_types::Body;
77
use pin_project::pin_project;
88

src/chunked/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::future::Future;
33
use std::pin::Pin;
44
use std::task::{Context, Poll};
55

6-
use async_std::io::{self, Read};
7-
use futures_core::ready;
6+
use futures_lite::io::{self, AsyncRead as Read};
7+
use futures_lite::ready;
88
use http_types::trailers::{Sender, Trailers};
99

1010
/// Decodes a chunked body according to

src/chunked/encoder.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::pin::Pin;
2+
use std::task::{Context, Poll};
23

3-
use async_std::io;
4-
use async_std::io::prelude::*;
5-
use async_std::task::{Context, Poll};
6-
use futures_core::ready;
4+
use futures_lite::io::AsyncRead as Read;
5+
use futures_lite::{io, ready};
76

87
/// An encoder for chunked encoding.
98
#[derive(Debug)]

src/client/decode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use async_std::io::{BufReader, Read};
2-
use async_std::prelude::*;
1+
use futures_lite::io::{AsyncRead as Read, BufReader};
2+
use futures_lite::prelude::*;
33
use http_types::{ensure, ensure_eq, format_err};
44
use http_types::{
55
headers::{CONTENT_LENGTH, DATE, TRANSFER_ENCODING},

src/client/encode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::io::Write;
22
use std::pin::Pin;
3+
use std::task::{Context, Poll};
34

4-
use async_std::io::{self, Cursor, Read};
5-
use async_std::task::{Context, Poll};
5+
use futures_lite::io::{self, AsyncRead as Read, Cursor};
66
use http_types::headers::{CONTENT_LENGTH, HOST, TRANSFER_ENCODING};
77
use http_types::{Method, Request};
88

src/client/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Process HTTP connections on the client.
22
3-
use async_std::io::{self, Read, Write};
3+
use futures_lite::io::{self, AsyncRead as Read, AsyncWrite as Write};
44
use http_types::{Request, Response};
55

66
mod decode;

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ mod read_notifier;
112112
pub mod client;
113113
pub mod server;
114114

115-
use async_std::io::Cursor;
116115
use body_encoder::BodyEncoder;
117116
pub use client::connect;
117+
use futures_lite::io::Cursor;
118118
pub use server::{accept, accept_with_opts, ServerOptions};
119119

120120
#[derive(Debug)]

src/read_notifier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::pin::Pin;
33
use std::task::{Context, Poll};
44

55
use async_channel::Sender;
6-
use async_std::io::{self, BufRead, Read};
6+
use futures_lite::io::{self, AsyncBufRead as BufRead, AsyncRead as Read};
77

88
/// ReadNotifier forwards [`async_std::io::Read`] and
99
/// [`async_std::io::BufRead`] to an inner reader. When the

src/server/body_reader.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use crate::chunked::ChunkedDecoder;
22
use async_dup::{Arc, Mutex};
3-
use async_std::io::{BufReader, Read, Take};
4-
use async_std::task::{Context, Poll};
5-
use std::{fmt::Debug, io, pin::Pin};
3+
use futures_lite::io::{AsyncRead as Read, BufReader, Take};
4+
use std::{
5+
fmt::Debug,
6+
io,
7+
pin::Pin,
8+
task::{Context, Poll},
9+
};
610

711
pub enum BodyReader<IO: Read + Unpin> {
812
Chunked(Arc<Mutex<ChunkedDecoder<BufReader<IO>>>>),

src/server/decode.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::str::FromStr;
44

55
use async_dup::{Arc, Mutex};
6-
use async_std::io::{BufReader, Read, Write};
7-
use async_std::{prelude::*, task};
6+
use futures_lite::io::{AsyncRead as Read, AsyncWrite as Write, BufReader};
7+
use futures_lite::prelude::*;
88
use http_types::content::ContentLength;
99
use http_types::headers::{EXPECT, TRANSFER_ENCODING};
1010
use http_types::{ensure, ensure_eq, format_err};
@@ -103,7 +103,7 @@ where
103103
let (body_read_sender, body_read_receiver) = async_channel::bounded(1);
104104

105105
if Some(CONTINUE_HEADER_VALUE) == req.header(EXPECT).map(|h| h.as_str()) {
106-
task::spawn(async move {
106+
async_global_executor::spawn(async move {
107107
// If the client expects a 100-continue header, spawn a
108108
// task to wait for the first read attempt on the body.
109109
if let Ok(()) = body_read_receiver.recv().await {
@@ -112,7 +112,8 @@ where
112112
// Since the sender is moved into the Body, this task will
113113
// finish when the client disconnects, whether or not
114114
// 100-continue was sent.
115-
});
115+
})
116+
.detach();
116117
}
117118

118119
// Check for Transfer-Encoding

src/server/encode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
33
use std::io::Write;
44
use std::pin::Pin;
5+
use std::task::{Context, Poll};
56
use std::time::SystemTime;
67

7-
use async_std::io::{self, Cursor, Read};
8-
use async_std::task::{Context, Poll};
8+
use futures_lite::io::{self, AsyncRead as Read, Cursor};
99
use http_types::headers::{CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
1010
use http_types::{Method, Response};
1111

src/server/mod.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Process HTTP connections on the server.
22
3-
use async_std::future::{timeout, Future, TimeoutError};
4-
use async_std::io::{self, Read, Write};
3+
use async_io::Timer;
4+
use futures_lite::io::{self, AsyncRead as Read, AsyncWrite as Write};
5+
use futures_lite::prelude::*;
56
use http_types::headers::{CONNECTION, UPGRADE};
67
use http_types::upgrade::Connection;
78
use http_types::{Request, Response, StatusCode};
8-
use std::{marker::PhantomData, time::Duration};
9+
use std::{future::Future, marker::PhantomData, time::Duration};
910
mod body_reader;
1011
mod decode;
1112
mod encode;
@@ -114,10 +115,16 @@ where
114115
let fut = decode(self.io.clone());
115116

116117
let (req, mut body) = if let Some(timeout_duration) = self.opts.headers_timeout {
117-
match timeout(timeout_duration, fut).await {
118-
Ok(Ok(Some(r))) => r,
119-
Ok(Ok(None)) | Err(TimeoutError { .. }) => return Ok(ConnectionStatus::Close), /* EOF or timeout */
120-
Ok(Err(e)) => return Err(e),
118+
match fut
119+
.or(async {
120+
Timer::after(timeout_duration).await;
121+
Ok(None)
122+
})
123+
.await
124+
{
125+
Ok(Some(r)) => r,
126+
Ok(None) => return Ok(ConnectionStatus::Close), /* EOF or timeout */
127+
Err(e) => return Err(e),
121128
}
122129
} else {
123130
match fut.await? {

0 commit comments

Comments
 (0)