Compile on windows
This commit is contained in:
parent
3157ff3cbb
commit
2faed6267e
3 changed files with 32 additions and 4 deletions
|
|
@ -7,5 +7,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
procfs = "0.14.1"
|
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
|
||||||
|
[target.'cfg(target_os="linux")'.dependencies]
|
||||||
|
procfs = "0.14.1"
|
||||||
|
|
|
||||||
10
src/lib.rs
10
src/lib.rs
|
|
@ -22,6 +22,8 @@ pub enum Error {
|
||||||
MessageUnknown,
|
MessageUnknown,
|
||||||
MessageCorrupt,
|
MessageCorrupt,
|
||||||
ConnectionReset,
|
ConnectionReset,
|
||||||
|
ProcFs(String),
|
||||||
|
NotSupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Error {
|
impl PartialEq for Error {
|
||||||
|
|
@ -56,6 +58,14 @@ impl PartialEq for Error {
|
||||||
ConnectionReset => true,
|
ConnectionReset => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
|
ProcFs(a) => match other {
|
||||||
|
ProcFs(b) => a == b,
|
||||||
|
_ => false,
|
||||||
|
},
|
||||||
|
NotSupported => match other {
|
||||||
|
NotSupported => true,
|
||||||
|
_ => false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,24 @@
|
||||||
use crate::message::PortDesc;
|
use crate::message::PortDesc;
|
||||||
use procfs::process::FDTarget;
|
use crate::Error;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
pub fn get_entries() -> Result<Vec<PortDesc>, Error> {
|
||||||
|
Err(Error::NotSupported)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn get_entries() -> Result<Vec<PortDesc>, Error> {
|
||||||
|
match get_entries_linux() {
|
||||||
|
Ok(v) => Ok(v),
|
||||||
|
Err(e) => Err(Error::ProcFs(format!("{:?}", e))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn get_entries_linux() -> procfs::ProcResult<Vec<PortDesc>> {
|
||||||
|
use procfs::process::FDTarget;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub fn get_entries() -> procfs::ProcResult<Vec<PortDesc>> {
|
|
||||||
let all_procs = procfs::process::all_processes()?;
|
let all_procs = procfs::process::all_processes()?;
|
||||||
|
|
||||||
// build up a map between socket inodes and process stat info. Ignore any
|
// build up a map between socket inodes and process stat info. Ignore any
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue