diff options
Diffstat (limited to 'src/unix.rs')
| -rw-r--r-- | src/unix.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/unix.rs b/src/unix.rs index f26dc8c..967c4fe 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -13,11 +13,15 @@ use std::process::exit; use std::sync::Arc; use std::sync::Mutex; use std::thread; +use crate::Session; -use libc::socket; +fn handle_server(session: Arc<Mutex<Session>>, stream: UnixStream) -> io::Result<()> { + todo!() +} -use crate::BString; -use crate::Session; +fn handle_client(stream: UnixStream) -> io::Result<()> { + todo!() +} fn user_function_res(sock: &OsStr) -> io::Result<()> { let sock = UnixStream::connect(sock)?; @@ -38,7 +42,9 @@ pub fn maybe_run_defined_function() { let program_name = program_name.as_bytes(); if !program_name.contains(&b'/') && program_name != b"pish" { if let Some(socket) = std::env::var_os("PISH_SOCKET") { - let _ = user_function_res(&socket); + if let Ok(stream) = UnixStream::connect(socket) { + let _ = handle_client(stream); + } exit(-1); } } @@ -126,8 +132,9 @@ pub fn listen(session: Arc<Mutex<Session>>) -> SocketDropper { Ok(se) if se.socket_running.is_none() => break, _ => (), } - if let Ok(_stream) = stream { - todo!("handle client") + if let Ok(stream) = stream { + let se = se.clone(); + thread::spawn(move || handle_server(se, stream)); } } }); |
