Skip to content

Commit

Permalink
chore: remove unused dependency subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
phucvinh57 committed Feb 11, 2024
1 parent 48af100 commit 74e88a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
23 changes: 23 additions & 0 deletions src-proxy/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ edition = "2021"

[dependencies]
libc = "0.2.152"
winapi = "0.3.9"
subprocess = { git = "https://github.com/hniksic/rust-subprocess" }
winapi = "0.3.9"
12 changes: 3 additions & 9 deletions src-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::io::{self, Read, Write};
mod metrics;
use metrics::handle_metrics;


enum Error {
Io(io::Error),
NoMoreInput,
Expand All @@ -19,7 +18,6 @@ impl fmt::Display for Error {
}
}


fn read_input<R: Read>(mut input: R) -> Result<String, Error> {
let mut buffer_size = [0; 4];
match input
Expand All @@ -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;
Expand All @@ -63,6 +60,3 @@ fn main() {
}
}
}



9 changes: 4 additions & 5 deletions src-proxy/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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<i32, Error> {
Expand Down

0 comments on commit 74e88a9

Please sign in to comment.