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

update to tokio 0.3 and bytes 0.6 #115

Merged
merged 5 commits into from
Nov 4, 2020
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
201 changes: 149 additions & 52 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ edition = "2018"
cargo-fuzz = true

[dependencies]
bytes = "0.5"
bytes = "0.6"
libfuzzer-sys = "0.3"
tokio-util = { version="0.3", features=["codec"] }
tokio-util = { version="0.5", features=["codec"] }
websocket-codec = { path = "../websocket-codec" }

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion hyper-websocket-lite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ edition = "2018"
[dependencies]
futures = "0.3"
hyper = "0.13"
websocket-codec = { version = "0.3.5", path = "../websocket-codec" }
websocket-codec = { version = "0.3.5" }
tokio = { version = "0.2", features=["macros"] }
tokio-util = { version = "0.3", features=["codec"] }
6 changes: 3 additions & 3 deletions websocket-codec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "websocket-codec"
description = "A Tokio codec for the websocket protocol"
version = "0.3.5"
version = "0.4.0"
authors = ["Tim Robinson <[email protected]>"]
repository = "https://github.com/1tgr/rust-websocket-lite"
license = "MIT"
Expand All @@ -10,11 +10,11 @@ edition = "2018"
[dependencies]
base64 = "0.12"
byteorder = "1"
bytes = "0.5"
bytes = "0.6"
httparse = "1"
rand = "0.7"
sha1 = "0.6"
tokio-util = { version="0.3", features=["codec"] }
tokio-util = { version="0.5", features=["codec"] }

[dev-dependencies]
assert-allocations = { path="../assert-allocations" }
Expand Down
18 changes: 9 additions & 9 deletions websocket-lite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
[package]
name = "websocket-lite"
description = "A fast, low-overhead WebSocket client"
version = "0.3.5"
version = "0.4.0"
authors = ["Tim Robinson <[email protected]>"]
repository = "https://github.com/1tgr/rust-websocket-lite"
license = "MIT"
edition = "2018"

[dependencies]
base64 = "0.12"
bytes = "0.5"
bytes = "0.6"
futures = "0.3"
native-tls = { version = "0.2", optional = true }
openssl = { version = "0.10", optional = true }
rand = "0.7"
tokio-util = {version= "0.3", features=["codec"]}
tokio-openssl = { version = "0.4.0-alpha.6", optional = true }
tokio-tls = { version = "0.3", optional = true }
tokio = {version="0.2", features=["tcp", "io-util"]}
tokio-util = {version= "0.5", features=["codec"]}
tokio-openssl = { version = "0.5", optional = true }
tokio-native-tls = { version = "0.2", optional = true }
tokio = {version="0.3", features=["net", "io-util"]}
url = "2"
websocket-codec = { version = "0.3.5", path = "../websocket-codec" }
websocket-codec = { version = "0.4", path = "../websocket-codec" }

[dev-dependencies]
structopt = "0.3"
tokio = { version = "0.2", features=["macros", "time", "io-std"] }
tokio = { version = "0.3", features=["macros", "time", "io-std", "rt-multi-thread"] }

[features]
default = ["ssl-native-tls"]
nightly = []
ssl-native-tls = ["native-tls", "tokio-tls"]
ssl-native-tls = ["native-tls", "tokio-native-tls"]
ssl-openssl = ["openssl", "tokio-openssl"]

## Uncomment to enable the SSLKEYLOGFILE environment variable when the ssl-openssl feature is used
Expand Down
4 changes: 2 additions & 2 deletions websocket-lite/examples/wsdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ async fn main() -> Result<()> {
sink.send(message).await?;
}

time::delay_for(eof_wait).await;
Ok(()) as Result<()>
time::sleep(eof_wait).await;
Ok(())
};

let recv_loop = async {
Expand Down
19 changes: 8 additions & 11 deletions websocket-lite/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ mod tests {
use std::str;
use std::task::{Context, Poll};

use tokio::io::{AsyncRead, AsyncWrite};
use tokio::runtime::Runtime;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

use crate::ClientBuilder;

Expand Down Expand Up @@ -272,7 +271,7 @@ mod tests {
}

impl<R: AsyncRead + Unpin, W: Unpin> AsyncRead for ReadWritePair<R, W> {
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<io::Result<()>> {
Pin::new(&mut self.get_mut().0).poll_read(cx, buf)
}
}
Expand Down Expand Up @@ -305,17 +304,15 @@ mod tests {
sec-websocket-accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\
\r\n";

#[test]
fn can_async_connect_on() -> Result<()> {
#[tokio::test]
async fn can_async_connect_on() -> Result<()> {
let mut input = Cursor::new(&RESPONSE[..]);
let mut output = Vec::new();

Runtime::new()?.block_on(async {
ClientBuilder::new("ws://localhost:8000/stream?query")?
.key(&base64::decode(b"dGhlIHNhbXBsZSBub25jZQ==")?)
.async_connect_on(ReadWritePair(&mut input, &mut output))
.await
})?;
ClientBuilder::new("ws://localhost:8000/stream?query")?
.key(&base64::decode(b"dGhlIHNhbXBsZSBub25jZQ==")?)
.async_connect_on(ReadWritePair(&mut input, &mut output))
.await.unwrap();

assert_eq!(REQUEST, str::from_utf8(&output)?);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions websocket-lite/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ mod inner {
pub async fn async_wrap<S: AsyncRead + AsyncWrite + Unpin>(
domain: String,
stream: S,
) -> Result<::tokio_tls::TlsStream<S>> {
) -> Result<tokio_native_tls::TlsStream<S>> {
let builder = TlsConnector::builder();
let cx = builder.build()?;
Ok(tokio_tls::TlsConnector::from(cx).connect(&domain, stream).await?)
Ok(tokio_native_tls::TlsConnector::from(cx).connect(&domain, stream).await?)
}

pub fn wrap<S: Read + Write + Debug + 'static>(domain: &str, stream: S) -> Result<::native_tls::TlsStream<S>> {
Expand Down
9 changes: 3 additions & 6 deletions websocket-lite/src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io::{Read, Write};
use std::mem::MaybeUninit;

use bytes::{BufMut, BytesMut};
use tokio_util::codec::{Decoder, Encoder};
Expand Down Expand Up @@ -59,12 +58,10 @@ impl<S: Read, C: Decoder> Framed<S, C> {
let buf = self.read_buf.bytes_mut();

let buf = unsafe {
for x in buf.iter_mut() {
*x.as_mut_ptr() = 0;
x.assume_init();
for i in 0..buf.len() {
buf.write_byte(i, 0);
}

&mut *(buf as *mut [MaybeUninit<u8>] as *mut [u8])
std::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len())
};

let n = self.stream.read(buf)?;
Expand Down