aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/command.rs
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2021-05-19 02:27:27 +0200
committerEskil Queseth <eskilq@kth.se>2021-05-19 02:27:27 +0200
commit5d05d292ddb7f8b28b71abd46930028b6e66dfde (patch)
treeabd10727e7c7e5ec004ec14ced7189d2c1c0687c /mumd/src/command.rs
parent0b2efad3e9aa569c27d339a5eca17c96155b4f9d (diff)
downloadmum-5d05d292ddb7f8b28b71abd46930028b6e66dfde.tar.gz
add support for sending multiple responses
Diffstat (limited to 'mumd/src/command.rs')
-rw-r--r--mumd/src/command.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/mumd/src/command.rs b/mumd/src/command.rs
index d101104..a1e8b21 100644
--- a/mumd/src/command.rs
+++ b/mumd/src/command.rs
@@ -5,13 +5,13 @@ use log::*;
use mumble_protocol::{Serverbound, control::ControlPacket};
use mumlib::command::{Command, CommandResponse};
use std::sync::{atomic::{AtomicU64, Ordering}, Arc, RwLock};
-use tokio::sync::{mpsc, oneshot, watch};
+use tokio::sync::{mpsc, watch};
pub async fn handle(
state: Arc<RwLock<State>>,
mut command_receiver: mpsc::UnboundedReceiver<(
Command,
- oneshot::Sender<mumlib::error::Result<Option<CommandResponse>>>,
+ mpsc::UnboundedSender<mumlib::error::Result<Option<CommandResponse>>>,
)>,
tcp_event_queue: TcpEventQueue,
ping_request_sender: mpsc::UnboundedSender<PingRequest>,
@@ -20,13 +20,13 @@ pub async fn handle(
) {
debug!("Begin listening for commands");
let ping_count = AtomicU64::new(0);
- while let Some((command, response_sender)) = command_receiver.recv().await {
+ while let Some((command, mut response_sender)) = command_receiver.recv().await {
debug!("Received command {:?}", command);
let mut state = state.write().unwrap();
let event = state.handle_command(command, &mut packet_sender, &mut connection_info_sender);
drop(state);
match event {
- ExecutionContext::TcpEvent(event, generator) => {
+ ExecutionContext::TcpEventCallback(event, generator) => {
tcp_event_queue.register_callback(
event,
Box::new(move |e| {
@@ -35,6 +35,14 @@ pub async fn handle(
}),
);
}
+ ExecutionContext::TcpEventSubscriber(event, mut handler) => {
+ tcp_event_queue.register_subscriber(
+ event,
+ Box::new(move |event| {
+ handler(event, &mut response_sender)
+ }),
+ )
+ }
ExecutionContext::Now(generator) => {
response_sender.send(generator()).unwrap();
}