45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
// Copyright (C) 2022 Infoshock Tech
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use crate::Result;
|
|
use std::path::Path;
|
|
use tokio::io::AsyncReadExt;
|
|
use tokio::net::UnixListener;
|
|
|
|
macro_rules! unwrap_or_continue {
|
|
($e:expr) => {
|
|
match $e {
|
|
Ok(v) => v,
|
|
Err(_) => continue,
|
|
}
|
|
};
|
|
}
|
|
|
|
// TODO: Accept some sort of handle to perform tasks on the WM
|
|
pub async fn listener_task(socket_path: &Path) -> Result<()> {
|
|
if socket_path.exists() {
|
|
std::fs::remove_file(socket_path)?;
|
|
}
|
|
let listener = UnixListener::bind(socket_path)?;
|
|
loop {
|
|
let (mut stream, _) = unwrap_or_continue!(listener.accept().await);
|
|
let mut buf = String::new();
|
|
|
|
stream.read_to_string(&mut buf).await?;
|
|
|
|
println!("{}", buf);
|
|
}
|
|
}
|