Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to tokio 1.0 #25

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
override: true
components: rustfmt
Comment on lines -60 to 62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this because CI failed on a formatting difference between stable and nightly. Since this crate is for stable rust it makes more sense to me to use stable formatting.


Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ categories = ["asynchronous", "cryptography", "network-programming"]
native-tls = "0.2.3"
thiserror = "1.0.9"
futures-util = { version = "0.3.1", features = ["io"], optional = true }
tokio = { version = "0.2.9", default-features = false, features = ["io-util"], optional = true }
tokio = { version = "1.0", default-features = false, features = ["io-util"], optional = true }
url = "2.1.1"

[features]
Expand All @@ -33,7 +33,7 @@ runtime-tokio = ["tokio"]
[dev-dependencies]
env_logger = "0.7.1"
async-std = { version = "1.6.0", features = ["attributes"] }
tokio = { version = "0.2.9", features = ["full"] }
tokio = { version = "1.0", features = ["full"] }
cfg-if = "0.1.10"
futures = "0.3.1"

Expand Down
15 changes: 15 additions & 0 deletions src/std_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ where
}
}

#[cfg(feature = "runtime-async-std")]
impl<S> Read for StdAdapter<S>
where
S: AsyncRead + Unpin,
Expand All @@ -43,6 +44,20 @@ where
}
}

#[cfg(feature = "runtime-tokio")]
impl<S> Read for StdAdapter<S>
where
S: AsyncRead + Unpin,
{
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut buf = tokio::io::ReadBuf::new(buf);
match self.with_context(|ctx, stream| stream.poll_read(ctx, &mut buf)) {
Poll::Ready(r) => r.map(|_| buf.filled().len()),
Poll::Pending => Err(io::Error::from(io::ErrorKind::WouldBlock)),
}
}
}

impl<S> Write for StdAdapter<S>
where
S: AsyncWrite + Unpin,
Expand Down
22 changes: 22 additions & 0 deletions src/tls_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl<S> TlsStream<S> {
}
}

#[cfg(feature = "runtime-async-std")]
impl<S> AsyncRead for TlsStream<S>
where
S: AsyncRead + AsyncWrite + Unpin,
Expand All @@ -87,6 +88,27 @@ where
}
}

#[cfg(feature = "runtime-tokio")]
impl<S> AsyncRead for TlsStream<S>
where
S: AsyncRead + AsyncWrite + Unpin,
{
fn poll_read(
mut self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &mut tokio::io::ReadBuf<'_>,
) -> Poll<io::Result<()>> {
match self.with_context(ctx, |s| cvt(s.read(buf.initialize_unfilled()))) {
Poll::Ready(Ok(len)) => {
buf.advance(len);
Poll::Ready(Ok(()))
}
Poll::Ready(Err(err)) => Poll::Ready(Err(err)),
Poll::Pending => Poll::Pending,
}
}
}

impl<S> AsyncWrite for TlsStream<S>
where
S: AsyncRead + AsyncWrite + Unpin,
Expand Down