Skip to content

Commit d01748d

Browse files
committed
Update for polling v3.0.0
Signed-off-by: John Nunley <[email protected]>
1 parent dcd10c0 commit d01748d

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ concurrent-queue = "2.2.0"
2929
futures-io = { version = "0.3.28", default-features = false, features = ["std"] }
3030
futures-lite = { version = "1.11.0", default-features = false }
3131
parking = "2.0.0"
32-
polling = "2.6.0"
32+
polling = "3.0.0"
3333
rustix = { version = "0.38.2", default-features = false, features = ["std", "fs"] }
3434
slab = "0.4.2"
3535
socket2 = { version = "0.5.3", features = ["all"] }
@@ -53,5 +53,4 @@ timerfd = "1"
5353
uds_windows = "1"
5454

5555
[patch.crates-io]
56-
polling = { git = "https://github.com/smol-rs/polling.git", branch = "notgull/unsafe2" }
5756
async-io = { path = "." }

src/reactor.rs

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::time::{Duration, Instant};
1515
use async_lock::OnceCell;
1616
use concurrent_queue::ConcurrentQueue;
1717
use futures_lite::ready;
18-
use polling::{Event, Poller};
18+
use polling::{Event, Events, Poller};
1919
use slab::Slab;
2020

2121
// Choose the proper implementation of `Registration` based on the target platform.
@@ -77,7 +77,7 @@ pub(crate) struct Reactor {
7777
/// Temporary storage for I/O events when polling the reactor.
7878
///
7979
/// Holding a lock on this event list implies the exclusive right to poll I/O.
80-
events: Mutex<Vec<Event>>,
80+
events: Mutex<Events>,
8181

8282
/// An ordered map of registered timers.
8383
///
@@ -104,7 +104,7 @@ impl Reactor {
104104
poller: Poller::new().expect("cannot initialize I/O event notification"),
105105
ticker: AtomicUsize::new(0),
106106
sources: Mutex::new(Slab::new()),
107-
events: Mutex::new(Vec::new()),
107+
events: Mutex::new(Events::new()),
108108
timers: Mutex::new(BTreeMap::new()),
109109
timer_ops: ConcurrentQueue::bounded(TIMER_QUEUE_SIZE),
110110
}
@@ -268,7 +268,7 @@ impl Reactor {
268268
/// A lock on the reactor.
269269
pub(crate) struct ReactorLock<'a> {
270270
reactor: &'a Reactor,
271-
events: MutexGuard<'a, Vec<Event>>,
271+
events: MutexGuard<'a, Events>,
272272
}
273273

274274
impl ReactorLock<'_> {
@@ -331,14 +331,16 @@ impl ReactorLock<'_> {
331331
// e.g. we were previously interested in both readability and writability,
332332
// but only one of them was emitted.
333333
if !state[READ].is_empty() || !state[WRITE].is_empty() {
334-
source.registration.modify(
335-
&self.reactor.poller,
336-
Event {
337-
key: source.key,
338-
readable: !state[READ].is_empty(),
339-
writable: !state[WRITE].is_empty(),
340-
},
341-
)?;
334+
// Create the event that we are interested in.
335+
let event = {
336+
let mut event = Event::none(source.key);
337+
event.readable = !state[READ].is_empty();
338+
event.writable = !state[WRITE].is_empty();
339+
event
340+
};
341+
342+
// Register interest in this event.
343+
source.registration.modify(&self.reactor.poller, event)?;
342344
}
343345
}
344346
}
@@ -463,14 +465,16 @@ impl Source {
463465

464466
// Update interest in this I/O handle.
465467
if was_empty {
466-
self.registration.modify(
467-
&Reactor::get().poller,
468-
Event {
469-
key: self.key,
470-
readable: !state[READ].is_empty(),
471-
writable: !state[WRITE].is_empty(),
472-
},
473-
)?;
468+
// Create the event that we are interested in.
469+
let event = {
470+
let mut event = Event::none(self.key);
471+
event.readable = !state[READ].is_empty();
472+
event.writable = !state[WRITE].is_empty();
473+
event
474+
};
475+
476+
// Register interest in it.
477+
self.registration.modify(&Reactor::get().poller, event)?;
474478
}
475479

476480
Poll::Pending
@@ -637,14 +641,20 @@ impl<H: Borrow<crate::Async<T>> + Clone, T> Future for Ready<H, T> {
637641

638642
// Update interest in this I/O handle.
639643
if was_empty {
640-
handle.borrow().source.registration.modify(
641-
&Reactor::get().poller,
642-
Event {
643-
key: handle.borrow().source.key,
644-
readable: !state[READ].is_empty(),
645-
writable: !state[WRITE].is_empty(),
646-
},
647-
)?;
644+
// Create the event that we are interested in.
645+
let event = {
646+
let mut event = Event::none(handle.borrow().source.key);
647+
event.readable = !state[READ].is_empty();
648+
event.writable = !state[WRITE].is_empty();
649+
event
650+
};
651+
652+
// Indicate that we are interested in this event.
653+
handle
654+
.borrow()
655+
.source
656+
.registration
657+
.modify(&Reactor::get().poller, event)?;
648658
}
649659

650660
Poll::Pending

src/reactor/kqueue.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Registration {
6363
poller.add_filter(PollSignal(signal.0), token, PollMode::Oneshot)
6464
}
6565
Self::Process(process) => poller.add_filter(
66-
Process::new(process, ProcessOps::Exit),
66+
unsafe { Process::new(process, ProcessOps::Exit) },
6767
token,
6868
PollMode::Oneshot,
6969
),
@@ -83,7 +83,7 @@ impl Registration {
8383
poller.modify_filter(PollSignal(signal.0), interest.key, PollMode::Oneshot)
8484
}
8585
Self::Process(process) => poller.modify_filter(
86-
Process::new(process, ProcessOps::Exit),
86+
unsafe { Process::new(process, ProcessOps::Exit) },
8787
interest.key,
8888
PollMode::Oneshot,
8989
),
@@ -100,7 +100,9 @@ impl Registration {
100100
poller.delete(fd)
101101
}
102102
Self::Signal(signal) => poller.delete_filter(PollSignal(signal.0)),
103-
Self::Process(process) => poller.delete_filter(Process::new(process, ProcessOps::Exit)),
103+
Self::Process(process) => {
104+
poller.delete_filter(unsafe { Process::new(process, ProcessOps::Exit) })
105+
}
104106
}
105107
}
106108
}

0 commit comments

Comments
 (0)