Struct udev::MonitorSocket
source · pub struct MonitorSocket { /* private fields */ }
Expand description
An active monitor that can receive events.
The events received by a Socket
match the filters set up by the Monitor
that created
the socket.
Monitors are initially set up to receive events from the kernel via a nonblocking socket. A
variant of poll()
should be used on the file descriptor returned by the AsRawFd
trait to
wait for new events.
Implementations§
source§impl Socket
impl Socket
sourcepub fn iter(&self) -> SocketIter<'_> ⓘ
pub fn iter(&self) -> SocketIter<'_> ⓘ
Create an iterator of socket event messages
Examples found in repository?
examples/monitor.rs (line 73)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
pub fn poll(socket: udev::MonitorSocket) -> io::Result<()> {
println!("Use syspoll");
let mut fds = vec![pollfd {
fd: socket.as_raw_fd(),
events: POLLIN,
revents: 0,
}];
loop {
let result = unsafe {
ppoll(
(&mut fds[..]).as_mut_ptr(),
fds.len() as nfds_t,
ptr::null_mut(),
ptr::null(),
)
};
if result < 0 {
return Err(io::Error::last_os_error());
}
let event = match socket.iter().next() {
Some(evt) => evt,
None => {
thread::sleep(Duration::from_millis(10));
continue;
}
};
super::print_event(event);
}
}
Trait Implementations§
source§impl AsFd for Socket
impl AsFd for Socket
Provides raw access to the monitor’s socket.
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Returns the file descriptor of the monitor’s socket.
source§impl AsRaw<udev_monitor> for Socket
impl AsRaw<udev_monitor> for Socket
Auto Trait Implementations§
impl RefUnwindSafe for Socket
impl !Send for Socket
impl !Sync for Socket
impl Unpin for Socket
impl UnwindSafe for Socket
Blanket Implementations§
source§impl<T> AsFilelike for Twhere
T: AsFd,
impl<T> AsFilelike for Twhere T: AsFd,
source§fn as_filelike(&self) -> BorrowedFd<'_>
fn as_filelike(&self) -> BorrowedFd<'_>
Borrows the reference. Read more
source§fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where
Target: FilelikeViewType,
fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>where Target: FilelikeViewType,
Return a borrowing view of a resource which dereferences to a
&Target
. Read moresource§impl<T> AsRawFilelike for Twhere
T: AsRawFd,
impl<T> AsRawFilelike for Twhere T: AsRawFd,
source§fn as_raw_filelike(&self) -> i32
fn as_raw_filelike(&self) -> i32
Returns the raw value.
source§impl<T> AsRawSocketlike for Twhere
T: AsRawFd,
impl<T> AsRawSocketlike for Twhere T: AsRawFd,
source§fn as_raw_socketlike(&self) -> i32
fn as_raw_socketlike(&self) -> i32
Returns the raw value.
source§impl<T> AsSocketlike for Twhere
T: AsFd,
impl<T> AsSocketlike for Twhere T: AsFd,
source§fn as_socketlike(&self) -> BorrowedFd<'_>
fn as_socketlike(&self) -> BorrowedFd<'_>
Borrows the reference.
source§fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where
Target: SocketlikeViewType,
fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>where Target: SocketlikeViewType,
Return a borrowing view of a resource which dereferences to a
&Target
. Read moresource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more