Skip to content

Commit

Permalink
Implement AsRawFd for EventLoop<'l, Data>
Browse files Browse the repository at this point in the history
This should allow inserting one `EventLoop` into the other.
  • Loading branch information
kchibisov committed Oct 9, 2023
1 parent 3cb03fb commit db238ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

#### Additions

- Implement `AsRawFd` for `EventLoop<'l, Data>`

#### Bugfixes

- Fix an issue, where id-reuse could execute a PostAction on a newly registered event source
Expand Down
14 changes: 14 additions & 0 deletions src/loop_logic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cell::{Cell, RefCell};
use std::fmt::Debug;
use std::os::unix::io::AsFd;
use std::os::unix::io::{AsRawFd, RawFd};
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
Expand Down Expand Up @@ -671,6 +672,19 @@ impl<'l, Data> EventLoop<'l, Data> {
}
}

impl<'l, Data> AsRawFd for EventLoop<'l, Data> {
/// Get the underlying raw-fd of the poller.
///
/// This could be used to create [`Generic`] source out of the current loop
/// and inserting into some other [`EventLoop`]. It's recommended to clone `fd`
/// before doing so.
///
/// [`Generic`]: crate::generic::Generic
fn as_raw_fd(&self) -> RawFd {
self.handle.inner.poll.borrow().poller.as_raw_fd()
}

Check warning on line 685 in src/loop_logic.rs

View check run for this annotation

Codecov / codecov/patch

src/loop_logic.rs#L683-L685

Added lines #L683 - L685 were not covered by tests
}

#[derive(Clone, Debug)]
/// The EventIterator is an `Iterator` over the events relevant to a particular source
/// This type is used in the [`EventSource::before_handle_events`] methods for
Expand Down
2 changes: 1 addition & 1 deletion src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub struct Token {
/// source and delegate the implementations to it.
pub struct Poll {
/// The handle to wepoll/epoll/kqueue/... used to poll for events.
poller: Arc<Poller>,
pub(crate) poller: Arc<Poller>,

/// The buffer of events returned by the poller.
events: RefCell<Events>,
Expand Down

0 comments on commit db238ed

Please sign in to comment.