Consume the pending signal count, returning the accumulated value. Returns `Ok(0)` if no signal was pending (EAGAIN on non-blocking fd). Returns `Ok(n)` where n is the accumulated signal count.
(&self)
| 71 | /// Returns `Ok(0)` if no signal was pending (EAGAIN on non-blocking fd). |
| 72 | /// Returns `Ok(n)` where n is the accumulated signal count. |
| 73 | pub fn try_read(&self) -> io::Result<u64> { |
| 74 | let mut val: u64 = 0; |
| 75 | // SAFETY: reading 8 bytes from a valid eventfd. |
| 76 | let ret = unsafe { |
| 77 | libc::read( |
| 78 | self.fd.as_raw_fd(), |
| 79 | &mut val as *mut u64 as *mut libc::c_void, |
| 80 | 8, |
| 81 | ) |
| 82 | }; |
| 83 | if ret < 0 { |
| 84 | let err = io::Error::last_os_error(); |
| 85 | if err.kind() == io::ErrorKind::WouldBlock { |
| 86 | Ok(0) |
| 87 | } else { |
| 88 | Err(err) |
| 89 | } |
| 90 | } else { |
| 91 | Ok(val) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /// Get the raw file descriptor for registration with an event loop. |
| 96 | /// |