From 335f9e7f59cf8a880b741cab058504f66de6c6c3 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Wed, 22 Dec 2021 10:19:54 -0800 Subject: [PATCH] switched to crrossbeam_channel from mpsc --- src/main.rs | 3 ++- src/modules/socket_handler.rs | 2 +- src/tests/socket_handler_tests.rs | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1127979..6cc9f92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use std::{sync::mpsc, time::Duration}; +use crossbeam_channel::unbounded; use modules::{socket_handler::Socket, stream_states::stream_states_class::StreamState, message_handler::{MessageHandler, StateMessage}}; use workctl::sync_flag; @@ -16,7 +17,7 @@ fn main() { let mut state = StreamState::new(); let socket_listener = Socket::make_listener(SERVER_ADDRESS); - let (from_socket_tx, from_socket_rx) = mpsc::channel::(); + let (from_socket_tx, from_socket_rx) = unbounded::(); let (mut listener_can_run_flag, listener_join_handle) = Socket::handle_connections(socket_listener, from_socket_tx); let (control_c_flag_tx, control_c_called_flag_rx) = sync_flag::new_syncflag(false); diff --git a/src/modules/socket_handler.rs b/src/modules/socket_handler.rs index 574ac8f..b233ae4 100644 --- a/src/modules/socket_handler.rs +++ b/src/modules/socket_handler.rs @@ -1,7 +1,7 @@ use workctl::sync_flag; use std::net::{TcpListener, TcpStream, Shutdown}; use std::io::{Read, Write}; -use std::sync::mpsc::Sender; +use crossbeam_channel::Sender; use std::thread::{self, JoinHandle}; use std::time::Duration; diff --git a/src/tests/socket_handler_tests.rs b/src/tests/socket_handler_tests.rs index 4a68180..2aa2497 100644 --- a/src/tests/socket_handler_tests.rs +++ b/src/tests/socket_handler_tests.rs @@ -1,4 +1,5 @@ use std::sync::mpsc; +use crossbeam_channel::unbounded; use std::io::{Write}; use std::thread; use std::time::Duration; @@ -31,7 +32,7 @@ fn panic_no_listener() { #[test] fn can_handle_messages() { let listener = Socket::make_listener("localhost:5004"); - let (tx_1, rx_1) = mpsc::channel::(); + let (tx_1, rx_1) = unbounded::(); let (mut flag, connection_handle) = Socket::handle_connections(listener, tx_1); @@ -52,7 +53,7 @@ fn can_handle_messages() { #[test] fn can_handle_delayed_messages() { let listener = Socket::make_listener("localhost:5005"); - let (tx_1, rx_1) = mpsc::channel::(); + let (tx_1, rx_1) = unbounded::(); let (mut flag, connection_handle) = Socket::handle_connections(listener, tx_1);