Support listening for file signal events#3250
Conversation
94e1a5e to
f58fd2f
Compare
|
👍 This design seems pretty elegant and should make it easier for us to implement some of epoll's api, and maybe other things too. |
|
I have a concern on this design. Without signals, it's fine to accidentally add more than one listeners to the event source, but, with them, it's not. Let's look at the fn refresh_listener(&mut self, weak_self: Weak<AtomicRefCell<Epoll>>, key: Key) {
let Some(entry) = self.monitoring.get_mut(&key) else {
return;
};
// Check what state we need to listen for this entry.
// We always listen for closed so we know when to stop monitoring the entry.
let listen = entry.get_listener_state().union(FileState::CLOSED);
let filter = StateListenerFilter::Always;
// Set up a callback so we get informed when the file changes.
let file = key.file().clone();
let handle =
file.borrow_mut()
.add_listener(listen, filter, move |state, changed, cb_queue| {
if let Some(epoll) = weak_self.upgrade() {
epoll
.borrow_mut()
.notify_entry(&key, state, changed, cb_queue);
}
});
entry.set_listener_handle(Some(handle));
}This seems to me that I can call Can you make sure that all the listeners of all the event sources actually call |
Each time I'm not completely on clear on the concern about multiple listeners receiving the same signal. And is the original "INPUT_BUFFER_PARITY" any different, I think you'd also see that state flag change on all listeners as well? |
Alright, got it. Thanks.
Yeah, it's probably not different. So, never mind :) |
|
I think this PR is great. I will do the edged-triggered epoll after this PR is merged. |
There is not yet a way to filter on specific signals.
f58fd2f to
80ffddf
Compare
We currently allow things to listen for state changes on files (ex: not readable -> readable), but there are cases where we want to listen for things that aren't state changes. For example edge-triggered epoll_wait()s will sometimes return if more bytes are written to a file's input buffer, even if the file's state didn't change (readable -> readable).
This adds the ability to emit signals from files, and to listen for them in the same way that you listen for state changes. This PR doesn't actually define any signals. For example listener callbacks were previously:
You can now write:
You emit signals using: