Skip to content

Commit

Permalink
feat: notify the client when server is ready to accept connections
Browse files Browse the repository at this point in the history
  • Loading branch information
vyfor committed Dec 6, 2024
1 parent 6313f45 commit b27d763
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ipc/pipe/platform/unix/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ impl PipeServerImpl for PipeServer {
let next_client_id = Arc::clone(&self.next_client_id);
let running = Arc::clone(&self.running);
let listener = self.listener.as_ref().unwrap().try_clone()?;
let notified = Arc::new(AtomicBool::new(false));

self.thread_handle = Some(std::thread::spawn(move || {
while running.load(Ordering::SeqCst) {
if !notified.load(Ordering::SeqCst) {
println!("Ready");
notified.store(true, Ordering::SeqCst);
}

match listener.accept() {
Ok((stream, _)) => {
let client_id = next_client_id.fetch_add(1, Ordering::SeqCst);
Expand Down
6 changes: 6 additions & 0 deletions src/ipc/pipe/platform/windows/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ impl PipeServerImpl for PipeServer {
let next_client_id = Arc::clone(&self.next_client_id);
let running = Arc::clone(&self.running);
let tx = self.tx.clone();
let notified = Arc::new(AtomicBool::new(false));

self.thread_handle = Some(std::thread::spawn(move || {
while running.load(Ordering::SeqCst) {
if let Ok(handle) = PipeServer::create_pipe_instance(&pipe_name) {
if !notified.load(Ordering::SeqCst) {
println!("Ready");
notified.store(true, Ordering::SeqCst);
}

unsafe {
let h_event =
CreateEventW(std::ptr::null_mut(), 1, 0, std::ptr::null_mut());
Expand Down

0 comments on commit b27d763

Please sign in to comment.