Skip to content

Commit

Permalink
fix: example compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
PrivateRookie committed Dec 3, 2023
1 parent 5293708 commit cc1f121
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 75 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ keywords = ["websocket", "proxy", "network"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
http = { path = "http_shim", optional = true, version = "0.10" }
http_shim = { path = "http_shim", optional = true, version = "0.0.1" }
thiserror = "1"
rand = "0.8"
base64 = "0.20"
Expand Down Expand Up @@ -59,7 +59,7 @@ hyper-util = { version = "0.1", optional = true }


[features]
default = ["sync", "simple", "sync_tls_rustls", "http/old"]
default = ["sync", "simple", "sync_tls_rustls", "http_shim/old"]
sync = []
sync_tls_rustls = ["sync", "rustls-connector", "rustls-pemfile"]
sync_tls_native = ["sync", "native-tls"]
Expand All @@ -76,8 +76,8 @@ async_tls_native = ["async", "tokio-native-tls"]
deflate = ["libz-sys"]
deflate_static = ["libz-sys/static"]
deflate_ng = ["libz-sys/zlib-ng"]
poem = ["dep:poem", "async", "http/old"]
axum = ["dep:axum", "dep:hyper", "dep:hyper-util", "async", "http/new"]
poem = ["dep:poem", "async", "http_shim/old"]
axum = ["dep:axum", "dep:hyper", "dep:hyper-util", "async", "http_shim/new"]
simple = ["deflate"]


Expand Down
1 change: 1 addition & 0 deletions examples/binance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::Parser;
use tracing::Level;
use tracing_subscriber::util::SubscriberInitExt;
use ws_tool::{
http,
codec::AsyncStringCodec,
connector::{async_tcp_connect, async_wrap_rustls, get_host},
ClientBuilder,
Expand Down
6 changes: 3 additions & 3 deletions examples/load_test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use clap::Parser;
use rayon::prelude::*;
use std::{
collections::HashMap,
net::TcpStream,
num::ParseIntError,
time::{Duration, Instant},
};

use clap::Parser;
use rayon::prelude::*;
use tracing::{info, Level};
use tracing_subscriber::util::SubscriberInitExt;
use ws_tool::http;
use ws_tool::{
codec::{BytesCodec, PMDConfig, WindowBit},
frame::OpCode::Close,
Expand Down
2 changes: 1 addition & 1 deletion examples/tls_proxy_deflate_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing_subscriber::util::SubscriberInitExt;
use ws_tool::{
codec::{DeflateCodec, PMDConfig, WindowBit},
frame::OpCode,
ClientBuilder, ClientConfig,
http, ClientBuilder, ClientConfig,
};

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions http_shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "http"
name = "http_shim"
edition = "2021"
version.workspace = true
version = "0.0.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
http1_0 = { package = "http", version = "1" }
http0_x = { package = "http", version = "0.*" }
http0_x = { package = "http", version = "0.2" }

[features]
default = []
Expand Down
33 changes: 0 additions & 33 deletions scripts/build.sh

This file was deleted.

54 changes: 54 additions & 0 deletions scripts/build_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

set -e
echo "building autobahn_async_client ..."
cargo build -q --example autobahn_async_client -F async

echo "building autobahn_async_deflate_client ..."
cargo build -q --example autobahn_async_deflate_client -F async -F deflate

echo "building autobahn_client ..."
cargo build -q --example autobahn_client

echo "building autobahn_deflate_client ..."
cargo build -q --example autobahn_deflate_client -F deflate

echo "building bench_async_server ..."
cargo build -q --example bench_async_server -F async

echo "building bench_deflate_server ..."
cargo build -q --example bench_deflate_server -F deflate

echo "building bench_fastwebsockets ..."
cargo build -q --example bench_fastwebsockets -F async

echo "building bench_server ..."
cargo build -q --example bench_server

echo "building bench_tungstenite ..."
cargo build -q --example bench_tungstenite -F async

echo "building binance ..."
cargo build -q --example binance -F async -F deflate -F async_tls_rustls

echo "building echo ..."
cargo build -q --example echo -F async

echo "building echo_async_server ..."
cargo build -q --example echo_async_server -F async -F async_tls_rustls

echo "building echo_server ..."
cargo build -q --example echo_server

echo "building ext_axum ..."
cargo build -q --example ext_axum -F axum --no-default-features

echo "building ext_poem ..."
cargo build -q --example ext_poem -F poem

echo "building load_test ..."
cargo build -q --example load_test -F deflate

echo "building tls_proxy_deflate_client ..."
cargo build -q --example tls_proxy_deflate_client

8 changes: 4 additions & 4 deletions src/codec/binary/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use bytes::Buf;
use std::borrow::Cow;
use std::io::{Read, Write};

use crate::http;
use crate::{
codec::{
FrameCodec, FrameConfig, FrameReadState, FrameRecv, FrameSend, FrameWriteState, Split,
Expand All @@ -11,6 +8,9 @@ use crate::{
protocol::standard_handshake_resp_check,
Message,
};
use bytes::Buf;
use std::borrow::Cow;
use std::io::{Read, Write};

macro_rules! impl_recv {
() => {
Expand Down
8 changes: 4 additions & 4 deletions src/codec/binary/non_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use bytes::Buf;
use std::borrow::Cow;
use tokio::io::{AsyncRead, AsyncWrite};

use crate::http;
use crate::{
codec::{
AsyncFrameCodec, AsyncFrameRecv, AsyncFrameSend, FrameConfig, FrameReadState,
Expand All @@ -12,6 +9,9 @@ use crate::{
protocol::standard_handshake_resp_check,
Message,
};
use bytes::Buf;
use std::borrow::Cow;
use tokio::io::{AsyncRead, AsyncWrite};

macro_rules! impl_recv {
() => {
Expand Down
6 changes: 3 additions & 3 deletions src/codec/deflate/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::io::{Read, Write};

use bytes::BytesMut;
use rand::random;

use crate::http;
use crate::{
codec::{apply_mask, FrameConfig, Split},
errors::{ProtocolError, WsError},
frame::{ctor_header, OpCode, OwnedFrame, SimplifiedHeader},
protocol::standard_handshake_resp_check,
};
use bytes::BytesMut;
use rand::random;

use super::{DeflateReadState, DeflateWriteState, PMDConfig};

Expand Down
2 changes: 1 addition & 1 deletion src/codec/deflate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::http;
use core::slice;
use std::{
ffi::{c_char, c_int, c_uint},
mem::{self, transmute, MaybeUninit},
};

/// permessage-deflate id
pub const EXT_ID: &str = "permessage-deflate";
/// server_no_context_takeover param
Expand Down
8 changes: 4 additions & 4 deletions src/codec/deflate/non_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use bytes::BytesMut;
use rand::random;
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};

use crate::http;
use crate::{
codec::{apply_mask, FrameConfig, Split},
errors::{ProtocolError, WsError},
frame::{ctor_header, OpCode, OwnedFrame, SimplifiedHeader},
protocol::standard_handshake_resp_check,
};
use bytes::BytesMut;
use rand::random;
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};

use super::{DeflateReadState, DeflateWriteState, PMDConfig};

Expand Down
4 changes: 2 additions & 2 deletions src/codec/frame/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bytes::BytesMut;

use super::{FrameConfig, FrameReadState, FrameWriteState};
use crate::http;
use crate::{
codec::{apply_mask, Split},
errors::WsError,
frame::{ctor_header, header_len, OpCode, OwnedFrame, SimplifiedHeader},
protocol::standard_handshake_resp_check,
};
use bytes::BytesMut;
use std::{
io::{IoSlice, Read, Write},
ops::Range,
Expand Down
1 change: 1 addition & 0 deletions src/codec/frame/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::errors::{ProtocolError, WsError};
use crate::frame::{get_bit, HeaderView, OpCode, SimplifiedHeader};
use crate::http;
use crate::protocol::{cal_accept_key, standard_handshake_req_check};
use bytes::BytesMut;
use std::fmt::Debug;
Expand Down
4 changes: 2 additions & 2 deletions src/codec/frame/non_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{io::IoSlice, ops::Range};

use crate::http;
use bytes::BytesMut;
use std::{io::IoSlice, ops::Range};
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};

use super::{apply_mask, FrameConfig, FrameReadState, FrameWriteState};
Expand Down
1 change: 1 addition & 0 deletions src/codec/text/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::http;
use crate::{
codec::{
FrameCodec, FrameConfig, FrameReadState, FrameRecv, FrameSend, FrameWriteState, Split,
Expand Down
1 change: 1 addition & 0 deletions src/codec/text/non_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::http;
use crate::{
codec::{
AsyncFrameCodec, AsyncFrameRecv, AsyncFrameSend, FrameConfig, FrameReadState,
Expand Down
12 changes: 6 additions & 6 deletions src/connector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use http::Uri;

use crate::http;
use crate::http::Uri;
use crate::{errors::WsError, protocol::Mode};

/// get websocket scheme
Expand All @@ -19,9 +19,9 @@ pub fn get_host(uri: &Uri) -> Result<&str, WsError> {

#[cfg(feature = "sync")]
mod blocking {
use std::net::TcpStream;

use crate::errors::WsError;
use crate::http;
use std::net::TcpStream;

use super::{get_host, get_scheme};

Expand Down Expand Up @@ -134,7 +134,7 @@ pub use blocking::*;

#[cfg(feature = "async")]
mod non_blocking {
use http::Uri;
use crate::http::Uri;
use tokio::net::TcpStream;

use crate::errors::WsError;
Expand Down Expand Up @@ -227,7 +227,7 @@ mod non_blocking {
Ok(tls_stream)
}

#[cfg(feature = "async_tls_rustls")]
#[cfg(feature = "async_tls_native")]
impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin> crate::codec::Split
for tokio_native_tls::TlsStream<S>
{
Expand Down
2 changes: 2 additions & 0 deletions src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#[cfg(feature = "poem")]
pub mod poem_ext {
use crate::errors::WsError;
use crate::http;
use poem::Body;
use std::future::Future;

Expand Down Expand Up @@ -74,6 +75,7 @@ pub mod poem_ext {
/// axum websocket extension
#[cfg(feature = "axum")]
pub mod axum_ext {
use crate::http;
use std::future::Future;

use axum::{body::Body, response::Response};
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use std::collections::HashMap;

pub use http;
pub use http_shim as http;

/// websocket error definitions
pub mod errors;
Expand Down Expand Up @@ -108,6 +108,7 @@ impl ClientBuilder {

#[cfg(feature = "sync")]
mod blocking {
use crate::http;
use std::{
io::{Read, Write},
net::TcpStream,
Expand Down Expand Up @@ -255,6 +256,7 @@ mod blocking {

#[cfg(feature = "async")]
mod non_blocking {
use crate::http;
use std::fmt::Debug;

use tokio::{
Expand Down
Loading

0 comments on commit cc1f121

Please sign in to comment.