diff --git a/src/main.rs b/src/main.rs index 65aa1df..239abfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,22 +15,29 @@ fn main() { let (from_socket_tx, from_socket_rx) = mpsc::channel::(); let (mut listener_can_run_flag, listener_join_handle) = Socket::handle_connections(socket_listener, from_socket_tx); - let (mut control_c_flag_tx, control_c_called_flag_rx) = sync_flag::new_syncflag(false); + let (control_c_flag_tx, control_c_called_flag_rx) = sync_flag::new_syncflag(false); - ctrlc::set_handler(move || { - control_c_flag_tx.set(true); - }).expect("control C handler failed!"); + setup_control_c(control_c_flag_tx); + //until control_c is caught, check the queue of incoming + //requests from the socket handler. while !control_c_called_flag_rx.get() { match from_socket_rx.recv_timeout(Duration::from_millis(100)) { Ok(message) => { println!("{}", message); + }, Err(_) => {continue}, } } - println!("ding"); + //Close the listener thread listener_can_run_flag.set(false); listener_join_handle.join().unwrap(); - } +} + +fn setup_control_c(mut control_c_flag_tx: sync_flag::SyncFlagTx) { + ctrlc::set_handler(move || { + control_c_flag_tx.set(true); + }).expect("control C handler failed!"); +}