aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/command.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-06-12 06:37:06 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-06-12 06:37:06 +0200
commitcf3f8c185cede889faccd3d55655a494ccd6f707 (patch)
tree149bb196e2a16cb8d297d03fc16f56f03c84dcfc /mumd/src/command.rs
parentdcd70175a98c83a3334d7980e5196bc866e04efb (diff)
parentb7701a6f61b525c116e29981f122a58552751f78 (diff)
downloadmum-cf3f8c185cede889faccd3d55655a494ccd6f707.tar.gz
Merge remote-tracking branch 'origin/invalid-cert'
Diffstat (limited to 'mumd/src/command.rs')
-rw-r--r--mumd/src/command.rs34
1 files changed, 20 insertions, 14 deletions
diff --git a/mumd/src/command.rs b/mumd/src/command.rs
index 410751a..2069178 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(
@@ -32,16 +29,25 @@ 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) => {
+ // 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);
+ let response_sender = response_sender.clone();
+ tcp_event_queue.register_callback(
+ event,
+ Box::new(move |e| {
+ // 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();
+ }
+ }
+ }),
+ );
+ }
}
ExecutionContext::TcpEventSubscriber(event, mut handler) => tcp_event_queue
.register_subscriber(