aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/main.rs
diff options
context:
space:
mode:
authorKapten Z∅∅m <55669224+default-username-852@users.noreply.github.com>2021-06-06 23:19:05 +0200
committerGitHub <noreply@github.com>2021-06-06 23:19:05 +0200
commit360b232de29f0104a8beb0c57e8defd9e54c9e6c (patch)
tree3595d6ae9dbe293ef0403ce581edd4742569147c /mumd/src/main.rs
parentea8b1906e14c3b319d3ad184b6d7cfc507c23b4f (diff)
parent55a12fbdfb435886b2f211fe1fb00daafb32b6a7 (diff)
downloadmum-360b232de29f0104a8beb0c57e8defd9e54c9e6c.tar.gz
Merge pull request #92 from mum-rs/text-message
Text message
Diffstat (limited to 'mumd/src/main.rs')
-rw-r--r--mumd/src/main.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/mumd/src/main.rs b/mumd/src/main.rs
index f298070..0c175c2 100644
--- a/mumd/src/main.rs
+++ b/mumd/src/main.rs
@@ -8,13 +8,14 @@ mod state;
use crate::state::State;
+use bytes::{BufMut, BytesMut};
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 std::io::ErrorKind;
+use tokio::{net::{UnixListener, UnixStream}, sync::mpsc};
use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};
-use bytes::{BufMut, BytesMut};
#[tokio::main]
async fn main() {
@@ -81,7 +82,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 +106,22 @@ 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 {
+ if e.kind() != ErrorKind::BrokenPipe { //if the client closed the connection, ignore logging the error
+ //we just assume that they just don't want any more packets
+ error!("Error sending response: {:?}", e);
+ }
+ break;
+ }
+ }
}
});
}