Skip to content

Commit

Permalink
Merge pull request #39 from ackintosh/rtnetlink-socket-error-message
Browse files Browse the repository at this point in the history
linux: Improve error message by including specific reasons
  • Loading branch information
jxs authored Nov 12, 2024
2 parents eadf211 + e2814ca commit 8ac0816
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,23 @@ where
return Poll::Ready(Ok(event));
}
if Pin::new(&mut self.conn).poll(cx).is_ready() {
return Poll::Ready(Err(socket_err()));
return Poll::Ready(Err(socket_err(
"rtnetlink socket closed. Connection has been terminated.",
)));
}
let message = ready!(self.messages.poll_next_unpin(cx)).ok_or_else(socket_err)??;
let message = match ready!(self.messages.poll_next_unpin(cx)) {
Some(Ok(message)) => message,
Some(Err(error)) => {
return Poll::Ready(Err(socket_err(&format!(
"rtnetlink socket closed. {error}"
))));
}
None => {
return Poll::Ready(Err(socket_err(
"rtnetlink socket closed. Empty message has been returned.",
)));
}
};
match message {
RtnlMessage::NewAddress(msg) => self.add_address(msg),
RtnlMessage::DelAddress(msg) => self.rem_address(msg),
Expand All @@ -122,8 +136,8 @@ where
}
}

fn socket_err() -> std::io::Error {
std::io::Error::new(ErrorKind::BrokenPipe, "rtnetlink socket closed")
fn socket_err(error: &str) -> std::io::Error {
std::io::Error::new(ErrorKind::BrokenPipe, error)
}

fn iter_nets(msg: AddressMessage) -> impl Iterator<Item = IpNet> {
Expand Down

0 comments on commit 8ac0816

Please sign in to comment.