Skip to content

Commit

Permalink
Flush all events before polling for read
Browse files Browse the repository at this point in the history
Once the udev socket becomes readable multiple events might be pulled
of. So all of them should be drained before polling for socket
readability again

Fixes: jeandudey#17

Signed-off-by: Sjoerd Simons <[email protected]>
  • Loading branch information
sjoerdsimons committed Mar 31, 2023
1 parent 8d9b695 commit ded0047
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tokio-udev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ impl Inner {
&mut self,
ctx: &mut std::task::Context,
) -> Poll<Option<Result<udev::Event, io::Error>>> {
match self.fd.poll_read_ready(ctx) {
Poll::Ready(Ok(mut ready_guard)) => {
ready_guard.clear_ready();
Poll::Ready(self.fd.get_mut().next().map(Ok))
loop {
if let Some(e) = self.fd.get_mut().next() {
return Poll::Ready(Some(Ok(e)));
}
match self.fd.poll_read_ready(ctx) {
Poll::Ready(Ok(mut ready_guard)) => {
ready_guard.clear_ready();
}
Poll::Ready(Err(err)) => return Poll::Ready(Some(Err(err))),
Poll::Pending => return Poll::Pending,
}
Poll::Ready(Err(err)) => Poll::Ready(Some(Err(err))),
Poll::Pending => Poll::Pending,
}
}
}

0 comments on commit ded0047

Please sign in to comment.