| 1 |
//! Eventfd based implementation of the ping event source. |
| 2 |
//! |
| 3 |
//! # Implementation notes |
| 4 |
//! |
| 5 |
//! The eventfd is a much lighter signalling mechanism provided by the Linux |
| 6 |
//! kernel. Rather than write an arbitrary sequence of bytes, it only has a |
| 7 |
//! 64-bit counter. |
| 8 |
//! |
| 9 |
//! To avoid closing the eventfd early, we wrap it in a RAII-style closer |
| 10 |
//! `CloseOnDrop` in `make_ping()`. When all the senders are dropped, another |
| 11 |
//! wrapper `FlagOnDrop` handles signalling this to the event source, which is |
| 12 |
//! the sole owner of the eventfd itself. The senders have weak references to |
| 13 |
//! the eventfd, and if the source is dropped before the senders, they will |
| 14 |
//! simply not do anything (except log a message). |
| 15 |
//! |
| 16 |
//! To differentiate between regular ping events and close ping events, we add 2 |
| 17 |
//! to the counter for regular events and 1 for close events. In the source we |
| 18 |
//! can then check the LSB and if it's set, we know it was a close event. This |
| 19 |
//! only works if a close event never fires more than once. |
| 20 |
|
| 21 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/io/::RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#, syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#}; |
| •22 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::IntoRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/IntoRawFd#; |
| •23 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#; |
| 24 |
|
| 25 |
use nixrust-analyzer cargo nix 0.30.1 crate/::sysrust-analyzer cargo nix 0.30.1 sys/::eventfdrust-analyzer cargo nix 0.30.1 sys/eventfd/::{eventfdrust-analyzer cargo nix 0.30.1 sys/eventfd/eventfd()., EfdFlagsrust-analyzer cargo nix 0.30.1 sys/eventfd/EfdFlags#}; |
| 26 |
use nixrust-analyzer cargo nix 0.30.1 crate/::unistdrust-analyzer cargo nix 0.30.1 unistd/::{readrust-analyzer cargo nix 0.30.1 unistd/read()., writerust-analyzer cargo nix 0.30.1 unistd/write().}; |
| 27 |
|
| 28 |
use superrust-analyzer cargo calloop 0.10.5 sources/ping/::{CloseOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/CloseOnDrop#, PingErrorrust-analyzer cargo calloop 0.10.5 sources/ping/PingError#}; |
| 29 |
use craterust-analyzer cargo calloop 0.10.5 crate/::{ |
| 30 |
genericrust-analyzer cargo calloop 0.10.5 sources/generic/::Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#, EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource#, Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#, Moderust-analyzer cargo calloop 0.10.5 sys/Mode#, Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#, Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#, |
| 31 |
}; |
| 32 |
|
| 33 |
// These are not bitfields! They are increments to add to the eventfd counter. |
| 34 |
// Since the fd can only be closed once, we can effectively use the |
| 35 |
// INCREMENT_CLOSE value as a bitmask when checking. |
| 36 |
const INCREMENT_PINGrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/INCREMENT_PING.: u64 = 0x2; |
| 37 |
const INCREMENT_CLOSErust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/INCREMENT_CLOSE.: u64 = 0x1; |
| 38 |
|
| 39 |
#[inline] |
| 40 |
pub fn make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/make_ping().() -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<(Pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/Ping#, PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#)> { |
| 41 |
let read = eventfdrust-analyzer cargo nix 0.30.1 sys/eventfd/eventfd().(0, EfdFlagsrust-analyzer cargo nix 0.30.1 sys/eventfd/EfdFlags#::EFD_CLOEXECrust-analyzer cargo nix 0.30.1 sys/eventfd/impl#[EfdFlags]EFD_CLOEXEC. rust-analyzer cargo nix 0.30.1 sys/eventfd/impl#[EfdFlags][`BitOr<Self>`]bitor().|rust-analyzer cargo nix 0.30.1 sys/eventfd/impl#[EfdFlags][`BitOr<Self>`]bitor(). rust-analyzer cargo nix 0.30.1 sys/eventfd/impl#[EfdFlags][`BitOr<Self>`]bitor().EfdFlagsrust-analyzer cargo nix 0.30.1 sys/eventfd/EfdFlags#::EFD_NONBLOCKrust-analyzer cargo nix 0.30.1 sys/eventfd/impl#[EfdFlags]EFD_NONBLOCK.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| •42 |
let read = read.into_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[OwnedFd][IntoRawFd]into_raw_fd().(); |
| 43 |
|
| 44 |
// We only have one fd for the eventfd. If the sending end closes it when |
| 45 |
// all copies are dropped, the receiving end will be closed as well. We need |
| 46 |
// to make sure the fd is not closed until all holders of it have dropped |
| 47 |
// it. |
| 48 |
|
| 49 |
let fd_arc = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(CloseOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/CloseOnDrop#(read)); |
| 50 |
|
| 51 |
let ping = Pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/Ping# { |
| 52 |
eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/Ping#event.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(FlagOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/FlagOnDrop#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&fd_arc))), |
| 53 |
}; |
| 54 |
|
| 55 |
let source = PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource# { |
| 56 |
eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#event.: Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#::newrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F>`]new().(read, Interestrust-analyzer cargo calloop 0.10.5 sys/Interest#::READrust-analyzer cargo calloop 0.10.5 sys/impl#[Interest]READ., Moderust-analyzer cargo calloop 0.10.5 sys/Mode#::Levelrust-analyzer cargo calloop 0.10.5 sys/Mode#Level#), |
| 57 |
_fdrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#_fd.: fd_arc, |
| 58 |
}; |
| 59 |
|
| 60 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((ping, source)) |
| 61 |
} |
| 62 |
|
| 63 |
// Helper functions for the event source IO. |
| 64 |
|
| 65 |
#[inline] |
| 66 |
fn send_pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/send_ping().(fd: RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#, count: u64) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 67 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(count >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). 0); |
| •68 |
match writerust-analyzer cargo nix 0.30.1 unistd/write().(unsafe { BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#::borrow_rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`]borrow_raw().(fd) }, &count.to_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]to_ne_bytes().()) { |
| 69 |
// The write succeeded, the ping will wake up the loop. |
| 70 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 71 |
|
| 72 |
// The counter hit its cap, which means previous calls to write() will |
| 73 |
// wake up the loop. |
| 74 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(nixrust-analyzer cargo nix 0.30.1 crate/::errnorust-analyzer cargo nix 0.30.1 errno/::Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::EAGAINrust-analyzer cargo nix 0.30.1 errno/consts/Errno#EAGAIN#) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 75 |
|
| 76 |
// Anything else is a real error. |
| 77 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
#[inline] |
| 82 |
fn drain_pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/drain_ping().(fd: RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u64> { |
| 83 |
// The eventfd counter is effectively a u64. |
| 84 |
const NBYTESrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/NBYTES.: usize = 8; |
| 85 |
let mut buf = [0u8; NBYTESrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/NBYTES.]; |
| 86 |
|
| •87 |
match readrust-analyzer cargo nix 0.30.1 unistd/read().(unsafe { BorrowedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/BorrowedFd#::borrow_rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/impl#[`BorrowedFd<'_>`]borrow_raw().(fd) }, &mut buf) { |
| 88 |
// Reading from an eventfd should only ever produce 8 bytes. No looping |
| 89 |
// is required. |
| 90 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(NBYTESrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/NBYTES.) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(u64::from_ne_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_ne_bytes().(buf)), |
| 91 |
|
| 92 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 93 |
|
| 94 |
// Any other error can be propagated. |
| 95 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
// The event source is simply a generic source with one of the eventfds. |
| 100 |
#[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 101 |
pub struct PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource# { |
| 102 |
eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#event.: Genericrust-analyzer cargo calloop 0.10.5 sources/generic/Generic#<RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#>, |
| 103 |
|
| 104 |
// This is held only to ensure that there is an owner of the fd that lives |
| 105 |
// as long as the Generic source, so that the fd is not closed unexpectedly |
| 106 |
// when all the senders are dropped. |
| 107 |
_fdrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#_fd.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<CloseOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/CloseOnDrop#>, |
| 108 |
} |
| 109 |
|
| 110 |
impl EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource# for PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource# { |
| 111 |
type Eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]Event# = (); |
| 112 |
type Metadatarust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]Metadata# = (); |
| 113 |
type Retrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]Ret# = (); |
| 114 |
type Errorrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]Error# = PingErrorrust-analyzer cargo calloop 0.10.5 sources/ping/PingError#; |
| 115 |
|
| 116 |
fn process_eventsrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]process_events().<C>( |
| 117 |
&mut self, |
| 118 |
readiness: Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#, |
| 119 |
token: Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, |
| 120 |
mut callback: C, |
| 121 |
) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, Selfrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]::Errorrust-analyzer cargo calloop 0.10.5 sources/EventSource#Error#> |
| 122 |
where |
| 123 |
C: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(Selfrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]::Eventrust-analyzer cargo calloop 0.10.5 sources/EventSource#Event#, &mut Selfrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]::Metadatarust-analyzer cargo calloop 0.10.5 sources/EventSource#Metadata#) -> Selfrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]::Retrust-analyzer cargo calloop 0.10.5 sources/EventSource#Ret#, |
| 124 |
{ |
| 125 |
self.eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#event. |
| 126 |
.process_eventsrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]process_events().(readiness, token, |_, &mut fd| { |
| 127 |
let counter = drain_pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/drain_ping().(fd)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 128 |
|
| 129 |
// If the LSB is set, it means we were closed. If anything else |
| 130 |
// is also set, it means we were pinged. The two are not |
| 131 |
// mutually exclusive. |
| 132 |
let close = (counter rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().INCREMENT_CLOSErust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/INCREMENT_CLOSE.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0; |
| 133 |
let ping = (counter rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().(u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().1)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0; |
| 134 |
|
| 135 |
if ping { |
| 136 |
callback((), &mut ()); |
| 137 |
} |
| 138 |
|
| 139 |
if close { |
| 140 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Removerust-analyzer cargo calloop 0.10.5 sources/PostAction#Remove#) |
| 141 |
} else { |
| 142 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#) |
| 143 |
} |
| 144 |
}) |
| 145 |
.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| PingErrorrust-analyzer cargo calloop 0.10.5 sources/ping/PingError#(e.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 146 |
} |
| 147 |
|
| 148 |
fn registerrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]register().(&mut self, poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, token_factory: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 149 |
self.eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#event..registerrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]register().(poll, token_factory) |
| 150 |
} |
| 151 |
|
| 152 |
fn reregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]reregister().( |
| 153 |
&mut self, |
| 154 |
poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, |
| 155 |
token_factory: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#, |
| 156 |
) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 157 |
self.eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#event..reregisterrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]reregister().(poll, token_factory) |
| 158 |
} |
| 159 |
|
| 160 |
fn unregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]unregister().(&mut self, poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 161 |
self.eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/PingSource#event..unregisterrust-analyzer cargo calloop 0.10.5 sources/generic/impl#[`Generic<F, E>`][EventSource]unregister().(poll) |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
#[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 166 |
pub struct Pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/Ping# { |
| 167 |
// This is an Arc because it's potentially shared with clones. The last one |
| 168 |
// dropped needs to signal to the event source via the eventfd. |
| 169 |
eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/Ping#event.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<FlagOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/FlagOnDrop#>, |
| 170 |
} |
| 171 |
|
| 172 |
impl Pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/Ping# { |
| 173 |
/// Send a ping to the `PingSource`. |
| 174 |
pub fn pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(&self) { |
| 175 |
if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = send_pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/send_ping().(self.eventrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/Ping#event..0rust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/FlagOnDrop#0. .0rust-analyzer cargo calloop 0.10.5 sources/ping/CloseOnDrop#0., INCREMENT_PINGrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/INCREMENT_PING.) { |
| 176 |
logrust-analyzer cargo log 0.4.17 crate/::warnrust-analyzer cargo log 0.4.17 macros/warn!!("[calloop] Failed to write a ping: {:?}", e); |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
/// This manages signalling to the PingSource when it's dropped. There should |
| 182 |
/// only ever be one of these per PingSource. |
| 183 |
#[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 184 |
struct FlagOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/FlagOnDrop#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<CloseOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/CloseOnDrop#>); |
| 185 |
|
| 186 |
impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for FlagOnDroprust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/FlagOnDrop# { |
| 187 |
fn droprust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[FlagOnDrop][Drop]drop().(&mut self) { |
| 188 |
if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = send_pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/send_ping().(self.0rust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/FlagOnDrop#0. .0rust-analyzer cargo calloop 0.10.5 sources/ping/CloseOnDrop#0., INCREMENT_CLOSErust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/INCREMENT_CLOSE.) { |
| 189 |
logrust-analyzer cargo log 0.4.17 crate/::warnrust-analyzer cargo log 0.4.17 macros/warn!!("[calloop] Failed to send close ping: {:?}", e); |
| 190 |
} |
| 191 |
} |
| 192 |
} |