Skip to content

Commit

Permalink
fix(network): bug that upload speed is not tabulated correctly (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxp1998 authored and imsnif committed Jan 14, 2020
1 parent 0edc6c2 commit be53165
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/os/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,28 @@ pub fn get_input(

let network_frames = network_interfaces
.iter()
.map(|iface| get_datalink_channel(iface));

let available_network_frames = network_frames
.clone()
.filter_map(Result::ok)
.collect::<Vec<_>>();
.filter(|iface| iface.is_up() && !iface.ips.is_empty())
.map(|iface| (iface, get_datalink_channel(iface)));

let (available_network_frames, network_interfaces) = {
let network_frames = network_frames.clone();
let mut available_network_frames = Vec::new();
let mut available_interfaces: Vec<NetworkInterface> = Vec::new();
for (iface, rx) in network_frames.filter_map(|(iface, channel)| {
if let Ok(rx) = channel {
Some((iface, rx))
} else {
None
}
}) {
available_interfaces.push(iface.clone());
available_network_frames.push(rx);
}
(available_network_frames, available_interfaces)
};

if available_network_frames.is_empty() {
for iface in network_frames {
for (_, iface) in network_frames {
if let Some(iface_error) = iface.err() {
if let ErrorKind::PermissionDenied = iface_error.kind() {
failure::bail!(eperm_message())
Expand Down

0 comments on commit be53165

Please sign in to comment.