diff --git a/src-proxy/Cargo.lock b/src-proxy/Cargo.lock index 0406947..d6c69f0 100644 --- a/src-proxy/Cargo.lock +++ b/src-proxy/Cargo.lock @@ -13,4 +13,27 @@ name = "proxy" version = "0.1.0" dependencies = [ "libc", + "winapi", ] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/src-proxy/Cargo.toml b/src-proxy/Cargo.toml index 3468453..ef63b06 100644 --- a/src-proxy/Cargo.toml +++ b/src-proxy/Cargo.toml @@ -5,5 +5,4 @@ edition = "2021" [dependencies] libc = "0.2.152" -winapi = "0.3.9" -subprocess = { git = "https://github.com/hniksic/rust-subprocess" } \ No newline at end of file +winapi = "0.3.9" \ No newline at end of file diff --git a/src-proxy/src/main.rs b/src-proxy/src/main.rs index af14c53..577dd21 100644 --- a/src-proxy/src/main.rs +++ b/src-proxy/src/main.rs @@ -4,7 +4,6 @@ use std::io::{self, Read, Write}; mod metrics; use metrics::handle_metrics; - enum Error { Io(io::Error), NoMoreInput, @@ -19,7 +18,6 @@ impl fmt::Display for Error { } } - fn read_input(mut input: R) -> Result { let mut buffer_size = [0; 4]; match input @@ -46,14 +44,13 @@ fn main() { let path = "\\\\.\\pipe\\tpulse"; loop { match read_input(io::stdin()) { - Ok(value) => - { + Ok(value) => { match handle_metrics(&path, &value) { Ok(()) => eprintln!("Send data successfully"), - Err(err) => eprintln!("Fail to send data due to: {}", err) + Err(err) => eprintln!("Fail to send data due to: {}", err), } io::stderr().write_all(value.as_bytes()).unwrap(); - }, + } Err(e) => { if let Error::NoMoreInput = e { break; @@ -63,6 +60,3 @@ fn main() { } } } - - - diff --git a/src-proxy/src/metrics.rs b/src-proxy/src/metrics.rs index 78d1660..4794e2f 100644 --- a/src-proxy/src/metrics.rs +++ b/src-proxy/src/metrics.rs @@ -1,8 +1,7 @@ - #[cfg(any(target_os = "linux", target = "macos"))] -use libc::{open, write, O_WRONLY, close}; -use std::io::Error; +use libc::{close, open, write, O_WRONLY}; use std::ffi::CString; +use std::io::Error; #[cfg(any(target_os = "linux", target = "macos"))] pub fn handle_metrics(pipe_name: &str, data: &str) -> Result<(), Error> { let c_pipe_name = CString::new(pipe_name).expect("Failed to convert pipe name to CString"); @@ -27,13 +26,13 @@ pub fn handle_metrics(pipe_name: &str, data: &str) -> Result<(), Error> { #[cfg(target_os = "windows")] use { std::ffi::OsStr, + std::io::Error, std::os::windows::ffi::OsStrExt, std::ptr, - std::io::Error, winapi::ctypes::c_void, winapi::um::fileapi::{CreateFileW, WriteFile, OPEN_EXISTING}, + winapi::um::winbase::FILE_FLAG_OVERLAPPED, winapi::um::winnt::{FILE_SHARE_READ, GENERIC_WRITE}, - winapi::um::winbase::FILE_FLAG_OVERLAPPED }; #[cfg(target_os = "windows")] fn connect_to_pipe(pipe_name: &str) -> Result {