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

source

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

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsFilelike for Twhere 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 Twhere T: AsRawFd,

source§

fn as_raw_filelike(&self) -> i32

Returns the raw value.
source§

impl<T> AsRawSocketlike for Twhere T: AsRawFd,

source§

fn as_raw_socketlike(&self) -> i32

Returns the raw value.
source§

impl<T> AsSocketlike for Twhere 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 Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.