heim_net/os/linux/
counters.rs

1//! Linux-specific extensions.
2//!
3//! Available only for `cfg(target_os = "linux")`
4
5use heim_common::prelude::*;
6use heim_common::Pid;
7
8use crate::{sys, IoCounters};
9
10/// Linux-specific extension for [IoCounters].
11///
12/// [IoCounters]: ../../struct.IoCounters.html
13pub trait IoCountersExt {
14    /// Returns packets amount which were dropped while sending them.
15    fn drop_sent(&self) -> u64;
16}
17
18#[cfg(target_os = "linux")]
19impl IoCountersExt for crate::IoCounters {
20    fn drop_sent(&self) -> u64 {
21        self.as_ref().drop_sent()
22    }
23}
24
25/// Returns stream which yield [IO counters] for each network interface for process with given `pid`.
26///
27/// **MUST** be used as `process::Process::net_io_counters()`
28///
29/// ## Compatibility
30///
31/// Implemented only for Linux for now. For other platforms will return an empty stream.
32#[doc(hidden)]
33pub fn io_counters_for_pid(pid: Pid) -> impl Stream<Item = Result<IoCounters>> {
34    sys::io_counters_for_pid(pid).map_ok(Into::into)
35}