MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / try_read

Method try_read

nodedb-bridge/src/eventfd.rs:73–93  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 ///

Callers 4

send_requestMethod · 0.80
recv_responseMethod · 0.80
eventfd_wake_on_pushFunction · 0.80
tpc_event_loopFunction · 0.80

Calls 3

kindMethod · 0.80
readFunction · 0.50
as_raw_fdMethod · 0.45

Tested by 2

eventfd_wake_on_pushFunction · 0.64
tpc_event_loopFunction · 0.64