| 1 |
|
| 2 |
|
| 3 |
use polling::{Event, Poller}; |
| 4 |
|
| 5 |
use std::fmt; |
| 6 |
use std::io::Result; |
| 7 |
use std::os::unix::io::{AsRawFd, BorrowedFd, RawFd}; |
| 8 |
|
| 9 |
|
| 10 |
#[doc(hidden)] |
| 11 |
pub struct Registration { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
raw: RawFd, |
| 19 |
} |
| 20 |
|
| 21 |
impl fmt::Debug for Registration { |
| 22 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 23 |
fmt::Debug::fmt(&self.raw, f) |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
impl Registration { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
pub(crate) unsafe fn new(f: BorrowedFd<'_>) -> Self { |
| 34 |
Self { raw: f.as_raw_fd() } |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
#[inline] |
| 39 |
pub(crate) fn add(&self, poller: &Poller, token: usize) -> Result<()> { |
| 40 |
|
| 41 |
unsafe { poller.add(self.raw, Event::none(token)) } |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
#[inline] |
| 46 |
pub(crate) fn modify(&self, poller: &Poller, interest: Event) -> Result<()> { |
| 47 |
|
| 48 |
let fd = unsafe { BorrowedFd::borrow_raw(self.raw) }; |
| 49 |
poller.modify(fd, interest) |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
#[inline] |
| 54 |
pub(crate) fn delete(&self, poller: &Poller) -> Result<()> { |
| 55 |
|
| 56 |
let fd = unsafe { BorrowedFd::borrow_raw(self.raw) }; |
| 57 |
poller.delete(fd) |
| 58 |
} |
| 59 |
} |