Skip to content

Commit 6344ea8

Browse files
committed
utils/pollable_channel: Add the ability to obtain BorrowedFd to rx
Previously we only provided RawFd. Signed-off-by: Matej Hrica <[email protected]>
1 parent 39e1da8 commit 6344ea8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/utils/src/pollable_channel.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::eventfd::{EventFd, EFD_NONBLOCK, EFD_SEMAPHORE};
22
use std::collections::VecDeque;
33
use std::io;
44
use std::io::ErrorKind;
5-
use std::os::fd::{AsRawFd, RawFd};
5+
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, RawFd};
66
use std::sync::{Arc, Mutex};
77

88
/// A multiple producer single consumer channel that can be listened to by a file descriptor
@@ -70,3 +70,11 @@ impl<T: Send> AsRawFd for PollableChannelReciever<T> {
7070
self.inner.eventfd.as_raw_fd()
7171
}
7272
}
73+
74+
impl<T: Send> AsFd for PollableChannelReciever<T> {
75+
fn as_fd(&self) -> BorrowedFd<'_> {
76+
// SAFETY: The lifetime of the fd is the same as the lifetime of self.inner.eventfd which
77+
// is the same as the lifetime of self.
78+
unsafe { BorrowedFd::borrow_raw(self.inner.eventfd.as_raw_fd()) }
79+
}
80+
}

0 commit comments

Comments
 (0)