aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/main.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/main.rs
parent0b2efad3e9aa569c27d339a5eca17c96155b4f9d (diff)
downloadmum-5d05d292ddb7f8b28b71abd46930028b6e66dfde.tar.gz
add support for sending multiple responses
Diffstat (limited to 'mumd/src/main.rs')
-rw-r--r--mumd/src/main.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/mumd/src/main.rs b/mumd/src/main.rs
index f298070..c34deab 100644
--- a/mumd/src/main.rs
+++ b/mumd/src/main.rs
@@ -12,7 +12,7 @@ use futures_util::{select, FutureExt, SinkExt, StreamExt};
use log::*;
use mumlib::command::{Command, CommandResponse};
use mumlib::setup_logger;
-use tokio::{net::{UnixListener, UnixStream}, sync::{mpsc, oneshot}};
+use tokio::{net::{UnixListener, UnixStream}, sync::mpsc};
use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};
use bytes::{BufMut, BytesMut};
@@ -81,7 +81,7 @@ async fn main() {
async fn receive_commands(
command_sender: mpsc::UnboundedSender<(
Command,
- oneshot::Sender<mumlib::error::Result<Option<CommandResponse>>>,
+ mpsc::UnboundedSender<mumlib::error::Result<Option<CommandResponse>>>,
)>,
) {
let socket = UnixListener::bind(mumlib::SOCKET_PATH).unwrap();
@@ -105,21 +105,18 @@ async fn receive_commands(
Err(_) => continue,
};
- let (tx, rx) = oneshot::channel();
+ let (tx, mut rx) = mpsc::unbounded_channel();
sender.send((command, tx)).unwrap();
- let response = match rx.await {
- Ok(r) => r,
- Err(_) => {
- error!("Internal command response sender dropped");
- Ok(None)
- }
- };
- let mut serialized = BytesMut::new();
- bincode::serialize_into((&mut serialized).writer(), &response).unwrap();
+ while let Some(response) = rx.recv().await {
+ let mut serialized = BytesMut::new();
+ bincode::serialize_into((&mut serialized).writer(), &response).unwrap();
- let _ = writer.send(serialized.freeze()).await;
+ if let Err(e) = writer.send(serialized.freeze()).await {
+ error!("Error sending response: {:?}", e);
+ }
+ }
}
});
}