Jelajahi Sumber

fd_readable: Need to clear read ready each call

Caleb James DeLisle 7 bulan lalu
induk
melakukan
a25ebf10c5
1 mengubah file dengan 13 tambahan dan 5 penghapusan
  1. 13 5
      rust/cjdns_sys/src/rffi/event_loop/fd_readable.rs

+ 13 - 5
rust/cjdns_sys/src/rffi/event_loop/fd_readable.rs

@@ -65,14 +65,22 @@ pub extern "C" fn Rffi_pollFdReadable(
         let fd = tokio::io::unix::AsyncFd::new(fd).unwrap();
         loop {
             tokio::select! {
-                _r = fd.readable() => {
-                    let _guard = GCL.lock();
-                    if active.load(Ordering::Relaxed) {
-                        unsafe { (frc.cb)(frc.cb_context); }
-                    } else {
+                r = fd.readable() => {
+                    if !active.load(Ordering::Relaxed) {
                         log::info!("Rffi_pollFdReadable down: active = false");
                         break;
                     }
+                    match r {
+                        Ok(mut x) => {
+                            let guard = GCL.lock();
+                            unsafe { (frc.cb)(frc.cb_context); }
+                            drop(guard);
+                            x.clear_ready();
+                        }
+                        Err(e) => {
+                            log::debug!("Rffi_pollFdReadable returned error: {e} - continuing");
+                        }
+                    }
                 }
                 _ = rx_kill.recv() => {
                     log::info!("Rffi_pollFdReadable down: rx_kill received");