- while let Ok(n) = recv(fd, &mut buf, MsgFlags::empty()) {
- println!("something on the netlink socket: {} bytes", n);
- let Ok(new_list) = crate::list::list_interfaces() else {
- continue;
- };
- handle_update(new_list);
+ let (complete_tx, complete_rx) = mpsc::channel();
+
+ std::thread::spawn(move || {
+ let mut buf = [0u8; 4096];
+
+ loop {
+ let mut fds = [
+ pollfd {
+ fd: sockfd.as_raw_fd(),
+ events: POLLIN,
+ revents: 0,
+ },
+ pollfd {
+ fd: pipe_rd.as_raw_fd(),
+ events: POLLIN,
+ revents: 0,
+ },
+ ];
+ unsafe {
+ poll(&mut fds as *mut _, 2, -1);
+ }
+ if fds[0].revents != 0 {
+ // netlink socket had something happen
+ if recv(sockfd.as_raw_fd(), &mut buf, MsgFlags::empty()).is_ok() {
+ let Ok(new_list) = crate::list::list_interfaces() else {
+ continue;
+ };
+ handle_update(new_list);
+ }
+ }
+ if fds[1].revents != 0 {
+ // pipe had something happen
+ break;
+ }