Skip to content

Commit

Permalink
Merge pull request #25 from dimbleby/polling-update
Browse files Browse the repository at this point in the history
polling 3.1.0
  • Loading branch information
dimbleby authored Sep 25, 2023
2 parents 35aeac3 + e38fb19 commit 8393e69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include = ["src/**/*", "LICENSE.txt", "README.md", "CHANGELOG.md"]
[dependencies]
c-ares = "7.6.0"
futures-channel = "0.3.9"
polling = "3.0.0"
polling = "3.1.0"

[dev-dependencies]
futures-executor = "0.3.9"
Expand Down
15 changes: 3 additions & 12 deletions src/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::thread;
use std::time::Duration;

use crate::error::Error;
use polling::Event;

// Indicate an interest in read and/or write events.
struct Interest(bool, bool);
Expand Down Expand Up @@ -70,7 +71,7 @@ impl EventLoop {
}
} else {
let key = usize::try_from(socket).unwrap();
let event = make_event(key, readable, writable);
let event = Event::new(key, readable, writable);
let interest = Interest(readable, writable);
if interests.insert(socket, interest).is_none() {
unsafe {
Expand Down Expand Up @@ -169,7 +170,7 @@ impl EventLoop {
let interests = self.interests.lock().unwrap();
if let Some(Interest(readable, writable)) = interests.get(&socket) {
let source = unsafe { borrow_socket(socket) };
let new_event = make_event(event.key, *readable, *writable);
let new_event = Event::new(event.key, *readable, *writable);
self.poller
.modify(source, new_event)
.expect("failed to update interest");
Expand All @@ -191,16 +192,6 @@ impl EventLoop {
}
}

// https://github.com/smol-rs/polling/issues/148
fn make_event(key: usize, readable: bool, writable: bool) -> polling::Event {
match (readable, writable) {
(true, true) => polling::Event::all(key),
(true, false) => polling::Event::readable(key),
(false, true) => polling::Event::writable(key),
_ => unreachable!(),
}
}

#[cfg(unix)]
unsafe fn borrow_socket(socket: c_ares::Socket) -> impl polling::AsSource {
BorrowedFd::borrow_raw(socket)
Expand Down

0 comments on commit 8393e69

Please sign in to comment.