added new function for listener struct

This commit is contained in:
Iris Pupo 2022-12-04 00:03:55 -05:00
parent 44d2ac693a
commit 01e2aee164
1 changed files with 17 additions and 8 deletions

View File

@ -66,6 +66,21 @@ impl DerefMut for Listener {
}
}
impl Listener {
fn new() -> std::io::Result<Self>{
let sock_dir = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR not set");
let sock_dir = Path::new(&sock_dir);
let sock_path = sock_dir.join(SOCK_NAME);
eprintln!("Making socket at: {:?}", sock_path);
let uds = UnixListener::bind(&sock_path)?;
let path = sock_path.to_path_buf();
Ok(Self{uds, path})
}
}
pub struct IpcData {
poll: Poll,
window_to_client_panel: HashMap<usize, (usize, PanelId)>,
@ -162,15 +177,8 @@ pub struct Ipc {
impl Ipc {
pub fn new(window_sender: WindowMessageSender) -> std::io::Result<(Self, IpcMessageSender)> {
let sock_dir = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR not set");
let sock_dir = Path::new(&sock_dir);
let sock_path = sock_dir.join(SOCK_NAME);
eprintln!("Making socket at: {:?}", sock_path);
let mut listener = Listener {
uds: UnixListener::bind(&sock_path)?,
path: sock_path.to_path_buf(),
};
let mut listener = Listener::new()?;
let mut signals = Signals::new(Signal::Interrupt | Signal::Quit)?;
@ -301,3 +309,4 @@ impl Ipc {
}
}
}