From 9f1d465ac411ef2efc5930bbdf56b8ea67b48690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 20:42:01 +0200 Subject: specify if we accept invalid server certs or not --- mumd/src/command.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 410751a..73ab3bd 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -32,16 +32,19 @@ pub async fn handle( &mut connection_info_sender, ); match event { - ExecutionContext::TcpEventCallback(event, generator) => { - tcp_event_queue.register_callback( - event, - Box::new(move |e| { - let response = generator(e); - for response in response { - response_sender.send(response).unwrap(); - } - }), - ); + ExecutionContext::TcpEventCallback(callbacks) => { + for (event, generator) in callbacks { + let response_sender = response_sender.clone(); + tcp_event_queue.register_callback( + event, + Box::new(move |e| { + let response = generator(e); + for response in response { + response_sender.send(response).unwrap(); + } + }), + ); + } } ExecutionContext::TcpEventSubscriber(event, mut handler) => tcp_event_queue .register_subscriber( -- cgit v1.2.1 From 7072e0fdc79fca1f8de07032dab163ef2a2d0e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 7 Jun 2021 23:02:30 +0200 Subject: only call one callback per event callback registration --- mumd/src/command.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 73ab3bd..2a3f148 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -4,10 +4,7 @@ use crate::state::{ExecutionContext, State}; use log::*; use mumble_protocol::{control::ControlPacket, Serverbound}; use mumlib::command::{Command, CommandResponse}; -use std::sync::{ - atomic::{AtomicU64, Ordering}, - Arc, RwLock, -}; +use std::{rc::Rc, sync::{Arc, RwLock, atomic::{AtomicBool, AtomicU64, Ordering}}}; use tokio::sync::{mpsc, watch}; pub async fn handle( @@ -33,14 +30,18 @@ pub async fn handle( ); match event { ExecutionContext::TcpEventCallback(callbacks) => { + let should_handle = Rc::new(AtomicBool::new(true)); for (event, generator) in callbacks { + let should_handle = Rc::clone(&should_handle); let response_sender = response_sender.clone(); tcp_event_queue.register_callback( event, Box::new(move |e| { - let response = generator(e); - for response in response { - response_sender.send(response).unwrap(); + if should_handle.fetch_and(false, Ordering::Relaxed) { + let response = generator(e); + for response in response { + response_sender.send(response).unwrap(); + } } }), ); -- cgit v1.2.1 From b7701a6f61b525c116e29981f122a58552751f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 18:40:05 +0200 Subject: AtomicBool::swap --- mumd/src/command.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 2a3f148..2069178 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -30,6 +30,7 @@ pub async fn handle( ); match event { ExecutionContext::TcpEventCallback(callbacks) => { + // A shared bool ensures that only one of the supplied callbacks is run. let should_handle = Rc::new(AtomicBool::new(true)); for (event, generator) in callbacks { let should_handle = Rc::clone(&should_handle); @@ -37,7 +38,8 @@ pub async fn handle( tcp_event_queue.register_callback( event, Box::new(move |e| { - if should_handle.fetch_and(false, Ordering::Relaxed) { + // If should_handle == true no other callback has been run yet. + if should_handle.swap(false, Ordering::Relaxed) { let response = generator(e); for response in response { response_sender.send(response).unwrap(); -- cgit v1.2.1