From 9a3c2ee89ea5373fd9ae4947cb91a1da424a4409 Mon Sep 17 00:00:00 2001 From: Prince Karikari Date: Wed, 28 Oct 2026 21:33:44 -0500 Subject: [PATCH] Issue #190 solved: remove dead code left over from the Rust migration Four things in the tree that nothing compiles or references: relay/src/ipc.rs is 113 lines behind a commented-out `// mod ipc;` in main.rs. relay/src/channel.rs is 6 lines that were never declared as a module at all. Neither is part of the crate, so neither is compiled. src/clientserver is a crate that cannot build: its Cargo.toml declares binaries at src/server.rs and src/client.rs, and neither file exists. Nothing references the crate. src/client.rs at the repo's src/ root is the orphan those binary paths were presumably meant to point at. The live IPC types are ToIpcThreadMessage and FromIpcThreadMessage in message.rs, which are untouched; the deleted ipc.rs is a separate unreferenced module. relay, src/server and baton all build, and the relay's test results are unchanged: 21 passed, 2 failed, the two failures being the mirror tests from #247 that also fail on clean main here. --- relay/src/channel.rs | 6 -- relay/src/ipc.rs | 113 ------------------------------------ relay/src/main.rs | 1 - src/client.rs | 35 ----------- src/clientserver/Cargo.lock | 7 --- src/clientserver/Cargo.toml | 14 ----- 6 files changed, 176 deletions(-) delete mode 100644 relay/src/channel.rs delete mode 100644 relay/src/ipc.rs delete mode 100644 src/client.rs delete mode 100644 src/clientserver/Cargo.lock delete mode 100644 src/clientserver/Cargo.toml diff --git a/relay/src/channel.rs b/relay/src/channel.rs deleted file mode 100644 index 34f00c7..0000000 --- a/relay/src/channel.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[derive(Debug, Clone, Default)] -pub enum ChannelMessage { - Connect, - #[default] - Disconnected, -} diff --git a/relay/src/ipc.rs b/relay/src/ipc.rs deleted file mode 100644 index 8e2de17..0000000 --- a/relay/src/ipc.rs +++ /dev/null @@ -1,113 +0,0 @@ -use interprocess::local_socket::traits::{Listener, ListenerExt}; - -use std::io::{BufRead, BufReader, Write}; - -use iced::time::Duration; - -use crate::IpcThreadMessage; - -// Pulled the IPC connection loop out into it's own crate/function -pub(crate) fn ipc_connection_loop( - listener: &impl Listener, - rx_kill: std::sync::mpsc::Receiver<()>, - txx: std::sync::mpsc::Sender, -) { - println!("ipc_connection_loop called!"); - - let mut buffer = String::with_capacity(128); - for conn in listener.incoming() { - let conn = match (rx_kill.try_recv(), conn) { - (Ok(()), _) => return, - (_, Ok(c)) => { - println!("success"); - c - } - (_, Err(e)) if e.kind() == std::io::ErrorKind::WouldBlock => continue, - (_, Err(e)) => { - eprintln!("Incoming connection failed: {e}"); - continue; - } - }; - - let mut conn = BufReader::new(conn); - println!("Incoming connection!"); - - // I think this is another connection test? seems redundant with the other stuff going on - match conn.read_line(&mut buffer) { - Ok(_) => (), - Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => continue, - _ => panic!(), - } - - let write_res = conn - .get_mut() - .write_all(b"Hello, from the relay prototype (Rust)!\n"); - - match write_res { - Ok(_) => (), - Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => continue, - _ => panic!(), - } - - print!("Client answered: {buffer}"); - buffer.clear(); - - // send frequency test -- three seconds of receiving 100,000 dummy inputs per second to check stability - // TODO: Remove these tests soon - println!("beginning frequency test..."); - let start = std::time::Instant::now(); - let mut recvs = vec![0, 0, 0]; - loop { - let elapsed = std::time::Instant::now() - start; - let idx = match elapsed { - dur if dur < Duration::from_secs(1) => 0, - dur if dur < Duration::from_secs(2) => 1, - dur if dur < Duration::from_secs(3) => 2, - _ => break, - }; - match conn.read_line(&mut buffer) { - Ok(_) => recvs[idx] += 1, - Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => continue, - _ => panic!(), - } - } - - println!("recvs: {recvs:?}"); - buffer.clear(); - - // Continuously receive data from Baton (plugin) - loop { - match conn.read_line(&mut buffer) { - Ok(s) if s == 0 || buffer.len() == 0 => { - buffer.clear(); - continue; - } - Ok(s) => { - let _ = buffer.pop(); // remove trailing newline - println!("Got: {buffer} ({s} bytes read)"); - - // txx is the sender half of channel from ipc_connection_handle -> main_gui_thread - - // TODO: change baton to send strings not floats, - // ^ UNABLE TO TEST THIS LOGIC UNTIL THAT HAPPENS - - // baton shutdown message received. Send shutdown message and break to next connection - // if the first 8 letters or so contains "SHUTDOWN", - if buffer.starts_with("SHUTDOWN") { - let _ = txx.send(IpcThreadMessage::BatonShutdown); - break; - } else { - // actual baton data received - let _ = txx.send(IpcThreadMessage::BatonData(buffer.clone())); - } - - buffer.clear(); - } - Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => continue, - Err(e) => panic!("Got err {e}"), - } - } - - println!("Onto next iteration of loop and connection!"); - } -} diff --git a/relay/src/main.rs b/relay/src/main.rs index cf51935..26a6a8b 100644 --- a/relay/src/main.rs +++ b/relay/src/main.rs @@ -1,5 +1,4 @@ mod bichannel; -// mod ipc; mod message; mod state; mod update; diff --git a/src/client.rs b/src/client.rs deleted file mode 100644 index 97a9cc5..0000000 --- a/src/client.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::io::{Read, Write}; -use std::net::TcpStream; -use std::str::from_utf8; - -fn main() -> std::io::Result<()> { - // Connect to the server - match TcpStream::connect("127.0.0.1:7878") { - Ok(mut stream) => { - println!("Successfully connected to server at 127.0.0.1:7878"); - - // Send a message to the server - let message = "Hello from the Rust TCP client!"; - stream.write(message.as_bytes())?; - println!("Sent: {}", message); - - // Buffer to store server response - let mut buffer = [0; 1024]; - match stream.read(&mut buffer) { - Ok(size) => { - // Convert the received bytes to a string - let response = from_utf8(&buffer[0..size]).unwrap(); - println!("Received: {}", response); - } - Err(e) => { - eprintln!("Failed to receive response: {}", e); - } - } - } - Err(e) => { - eprintln!("Failed to connect: {}", e); - } - } - - Ok(()) -} \ No newline at end of file diff --git a/src/clientserver/Cargo.lock b/src/clientserver/Cargo.lock deleted file mode 100644 index 22d8103..0000000 --- a/src/clientserver/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "clientserver" -version = "0.1.0" diff --git a/src/clientserver/Cargo.toml b/src/clientserver/Cargo.toml deleted file mode 100644 index 95f6698..0000000 --- a/src/clientserver/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "clientserver" -version = "0.1.0" -edition = "2021" - -[dependencies] - -[[bin]] -name = "server" -path = "src/server.rs" - -[[bin]] -name = "client" -path = "src/client.rs"