From 670a00100e2d75f9a0a8ed137b86239c49646c2a Mon Sep 17 00:00:00 2001 From: Hamza Jadid Date: Sat, 30 Dec 2023 12:30:14 +0200 Subject: [PATCH] feat: added static channel sizes --- jarust/src/jaconfig.rs | 10 ++++++---- jarust/src/jahandle.rs | 5 +++-- jarust/src/nsp_registry.rs | 3 ++- jarust/src/plugins/echotest/handle.rs | 3 ++- jarust/src/transport/wss.rs | 3 ++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/jarust/src/jaconfig.rs b/jarust/src/jaconfig.rs index 3769a0d..92989fe 100644 --- a/jarust/src/jaconfig.rs +++ b/jarust/src/jaconfig.rs @@ -1,9 +1,11 @@ +pub(crate) const CHANNEL_BUFFER_SIZE: usize = 32; + #[derive(Debug)] pub struct JaConfig { - pub uri: String, - pub apisecret: Option, - pub transport_type: TransportType, - pub root_namespace: String, + pub(crate) uri: String, + pub(crate) apisecret: Option, + pub(crate) transport_type: TransportType, + pub(crate) root_namespace: String, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/jarust/src/jahandle.rs b/jarust/src/jahandle.rs index e36877d..61485cd 100644 --- a/jarust/src/jahandle.rs +++ b/jarust/src/jahandle.rs @@ -1,3 +1,4 @@ +use crate::jaconfig::CHANNEL_BUFFER_SIZE; use crate::japrotocol::JaHandleRequestProtocol; use crate::japrotocol::JaResponse; use crate::japrotocol::JaResponseProtocol; @@ -52,8 +53,8 @@ impl JaHandle { mut receiver: mpsc::Receiver, id: u64, ) -> (Self, mpsc::Receiver) { - let (ack_sender, ack_receiver) = mpsc::channel(100); - let (event_sender, event_receiver) = mpsc::channel(100); + let (ack_sender, ack_receiver) = mpsc::channel(CHANNEL_BUFFER_SIZE); + let (event_sender, event_receiver) = mpsc::channel(CHANNEL_BUFFER_SIZE); let join_handle = tokio::spawn(async move { while let Some(item) = receiver.recv().await { diff --git a/jarust/src/nsp_registry.rs b/jarust/src/nsp_registry.rs index 2ebe8e4..feda439 100644 --- a/jarust/src/nsp_registry.rs +++ b/jarust/src/nsp_registry.rs @@ -1,3 +1,4 @@ +use crate::jaconfig::CHANNEL_BUFFER_SIZE; use crate::japrotocol::JaResponse; use crate::prelude::*; use std::collections::HashMap; @@ -34,7 +35,7 @@ impl NamespaceRegistry { } pub(crate) fn create_namespace(&mut self, namespace: &str) -> mpsc::Receiver { - let (tx, rx) = mpsc::channel(10); + let (tx, rx) = mpsc::channel(CHANNEL_BUFFER_SIZE); { self.write() .unwrap() diff --git a/jarust/src/plugins/echotest/handle.rs b/jarust/src/plugins/echotest/handle.rs index a28ae16..6627b59 100644 --- a/jarust/src/plugins/echotest/handle.rs +++ b/jarust/src/plugins/echotest/handle.rs @@ -1,5 +1,6 @@ use super::events::EchoTestPluginData; use super::messages::EchoTestStartMsg; +use crate::jaconfig::CHANNEL_BUFFER_SIZE; use crate::jahandle::JaHandle; use crate::japrotocol::JaEventProtocol; use crate::japrotocol::JaResponseProtocol; @@ -33,7 +34,7 @@ impl EchoTest for JaSession { &self, ) -> JaResult<(EchoTestHandle, mpsc::Receiver)> { let (handle, mut receiver) = self.attach(PLUGIN_ID).await?; - let (tx, rx) = mpsc::channel(100); + let (tx, rx) = mpsc::channel(CHANNEL_BUFFER_SIZE); tokio::spawn(async move { while let Some(msg) = receiver.recv().await { let msg = match msg.janus { diff --git a/jarust/src/transport/wss.rs b/jarust/src/transport/wss.rs index e8eb8e9..e1ecc69 100644 --- a/jarust/src/transport/wss.rs +++ b/jarust/src/transport/wss.rs @@ -1,4 +1,5 @@ use super::trans::Transport; +use crate::jaconfig::CHANNEL_BUFFER_SIZE; use crate::prelude::*; use async_trait::async_trait; use futures_util::stream::SplitSink; @@ -35,7 +36,7 @@ impl Transport for WebsocketTransport { headers.insert("Sec-Websocket-Protocol", "janus-protocol".parse()?); let (stream, _) = connect_async(request).await?; let (sender, mut receiver) = stream.split(); - let (tx, rx) = mpsc::channel(32); + let (tx, rx) = mpsc::channel(CHANNEL_BUFFER_SIZE); let forward_join_handle = tokio::spawn(async move { while let Some(Ok(message)) = receiver.next().await {