Struct 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

Source

pub fn iter(&self) -> SocketIter<'_>

Create an iterator of socket event messages

Examples found in repository?
examples/monitor.rs (line 80)
58    pub fn poll(socket: udev::MonitorSocket) -> io::Result<()> {
59        println!("Use syspoll");
60        let mut fds = vec![pollfd {
61            fd: socket.as_raw_fd(),
62            events: POLLIN,
63            revents: 0,
64        }];
65
66        loop {
67            let result = unsafe {
68                ppoll(
69                    (&mut fds[..]).as_mut_ptr(),
70                    fds.len() as nfds_t,
71                    ptr::null_mut(),
72                    ptr::null(),
73                )
74            };
75
76            if result < 0 {
77                return Err(io::Error::last_os_error());
78            }
79
80            let event = match socket.iter().next() {
81                Some(evt) => evt,
82                None => {
83                    thread::sleep(Duration::from_millis(10));
84                    continue;
85                }
86            };
87
88            super::print_event(event);
89        }
90    }

Trait Implementations§

Source§

impl AsFd for Socket

Provides raw access to the monitor’s socket.

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Returns the file descriptor of the monitor’s socket.

Source§

impl AsRaw<udev_monitor> for Socket

Source§

fn as_raw(&self) -> *mut udev_monitor

Get a reference of the underlying struct. Read more
Source§

fn into_raw(self) -> *mut udev_monitor

Convert the object into the underlying pointer. Read more
Source§

impl AsRawFd for Socket

Provides raw access to the monitor’s socket.

Source§

fn as_raw_fd(&self) -> RawFd

Returns the file descriptor of the monitor’s socket.

Auto Trait Implementations§

§

impl Freeze for Socket

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsFilelike for T
where T: AsFd,

Source§

fn as_filelike(&self) -> BorrowedFd<'_>

Borrows the reference. Read more
Source§

fn as_filelike_view<Target>(&self) -> FilelikeView<'_, Target>
where Target: FilelikeViewType,

Return a borrowing view of a resource which dereferences to a &Target. Read more
Source§

impl<T> AsRawFilelike for T
where T: AsRawFd,

Source§

fn as_raw_filelike(&self) -> i32

Returns the raw value.
Source§

impl<T> AsRawSocketlike for T
where T: AsRawFd,

Source§

fn as_raw_socketlike(&self) -> i32

Returns the raw value.
Source§

impl<T> AsSocketlike for T
where T: AsFd,

Source§

fn as_socketlike(&self) -> BorrowedFd<'_>

Borrows the reference.
Source§

fn as_socketlike_view<Target>(&self) -> SocketlikeView<'_, Target>
where Target: SocketlikeViewType,

Return a borrowing view of a resource which dereferences to a &Target. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.