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

feat(websocket client): WIP V2 ring buffer channel #165

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ parking_lot = "0.11.1"
pin-project = "1.0.1"
jsonrpsee-proc-macros = { path = "proc-macros" }
rand = "0.7.3"
ring-channel = { git = "https://github.com/niklasad1/ring-channel.git", branch = "na-atomicptr" }
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Were you planning to open a PR for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's up to the author of the library, he doesn't seem to be very keen on using AtomicPtr instead of NonNullPtr let's see how it goes. However, the idea is to split this PR into two parts when it works properly

  1. Extract try_send/send.now_or_never into a separate PR and handle the errors without ring channel crate
  2. Support for ring channel for ring channel.

serde = { version = "1.0.117", default-features = false, features = ["derive"] }
serde_json = "1.0.59"
smallvec = { version = "1.5.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_std::task::block_on;
use criterion::*;
use futures::channel::oneshot::{self, Sender};
use jsonrpsee::client::{HttpClient, HttpConfig, WsClient};
use jsonrpsee::client::{HttpClient, HttpConfig, WsClient, WsConfig};
use jsonrpsee::http::HttpServer;
use jsonrpsee::types::jsonrpc::{JsonValue, Params};
use jsonrpsee::ws::WsServer;
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn websocket_requests(c: &mut criterion::Criterion) {
let (tx_addr, rx_addr) = oneshot::channel::<SocketAddr>();
async_std::task::spawn(ws_server(tx_addr));
let server_addr = block_on(rx_addr).unwrap();
let client = Arc::new(block_on(WsClient::new(&format!("ws://{}", server_addr))).unwrap());
let client = Arc::new(block_on(WsClient::new(&format!("ws://{}", server_addr), WsConfig::default())).unwrap());

c.bench_function("synchronous WebSocket round trip", |b| {
b.iter(|| {
Expand Down
5 changes: 3 additions & 2 deletions examples/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

use async_std::task;
use futures::channel::oneshot::{self, Sender};
use jsonrpsee::client::{WsClient, WsSubscription};
use jsonrpsee::client::{WsClient, WsConfig, WsSubscription};
use jsonrpsee::types::jsonrpc::{JsonValue, Params};
use jsonrpsee::ws::WsServer;
use std::num::NonZeroUsize;

const SOCK_ADDR: &str = "127.0.0.1:9966";
const SERVER_URI: &str = "ws://localhost:9966";
Expand All @@ -44,7 +45,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});

server_started_rx.await?;
let client = WsClient::new(SERVER_URI).await?;
let client = WsClient::new(SERVER_URI, WsConfig::default()).await?;
let mut subscribe_hello: WsSubscription<JsonValue> =
client.subscribe("subscribe_hello", Params::None, "unsubscribe_hello").await?;

Expand Down
5 changes: 3 additions & 2 deletions examples/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

use async_std::task;
use futures::channel::oneshot::{self, Sender};
use jsonrpsee::client::WsClient;
use jsonrpsee::client::{WsClient, WsConfig};
use jsonrpsee::types::jsonrpc::{JsonValue, Params};
use jsonrpsee::ws::WsServer;
use std::num::NonZeroUsize;

const SOCK_ADDR: &str = "127.0.0.1:9944";
const SERVER_URI: &str = "ws://localhost:9944";
Expand All @@ -43,7 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});

server_started_rx.await?;
let client = WsClient::new(SERVER_URI).await?;
let client = WsClient::new(SERVER_URI, WsConfig::default()).await?;
let response: JsonValue = client.request("say_hello", Params::None).await?;
println!("r: {:?}", response);

Expand Down
4 changes: 3 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ mod ws;
#[cfg(feature = "http")]
pub use http::{HttpClient, HttpConfig, HttpTransportClient};
#[cfg(feature = "ws")]
pub use ws::{Client as WsClient, RawClient as RawWsClient, Subscription as WsSubscription, WsTransportClient};
pub use ws::{
Client as WsClient, Config as WsConfig, RawClient as RawWsClient, Subscription as WsSubscription, WsTransportClient,
};
Loading