[][src]Struct libuv::handles::poll::PollHandle

pub struct PollHandle { /* fields omitted */ }

Poll handles are used to watch file descriptors for readability, writability and disconnection similar to the purpose of poll(2).

The purpose of poll handles is to enable integrating external libraries that rely on the event loop to signal it about the socket status changes, like c-ares or libssh2. Using PollHandle for any other purpose is not recommended; TcpHandle, UdpHandle, etc. provide an implementation that is faster and more scalable than what can be achieved with PollHandle, especially on Windows.

It is possible that poll handles occasionally signal that a file descriptor is readable or writable even when it isn’t. The user should therefore always be prepared to handle EAGAIN or equivalent when it attempts to read from or write to the fd.

It is not okay to have multiple active poll handles for the same socket, this can cause libuv to busyloop or otherwise malfunction.

The user should not close a file descriptor while it is being polled by an active poll handle. This can cause the handle to report an error, but it might also start polling another socket. However the fd can be safely closed immediately after a call to stop() or close().

Note: On windows only sockets can be polled with poll handles. On Unix any file descriptor that would be accepted by poll(2) can be used.

Note: On AIX, watching for disconnection is not supported.

Implementations

impl PollHandle[src]

pub fn new(r#loop: &Loop, fd: File) -> Result<PollHandle>[src]

Create and initialize a new poll handle using a file descriptor

pub fn new_socket(r#loop: &Loop, socket: Socket) -> Result<PollHandle>[src]

Create and initialize a new poll handle using a socket descriptor. On Unix this is identical to new(). On windows it takes a SOCKET handle.

pub fn start<CB: Into<PollCB<'static>>>(
    &mut self,
    events: PollEvents,
    cb: CB
) -> Result<()>
[src]

Starts polling the file descriptor. events is a bitmask made up of READABLE, WRITABLE, PRIORITIZED and DISCONNECT. As soon as an event is detected the callback will be called with status set to 0, and the detected events set on the events field.

The PRIORITIZED event is used to watch for sysfs interrupts or TCP out-of-band messages.

The DISCONNECT event is optional in the sense that it may not be reported and the user is free to ignore it, but it can help optimize the shutdown path because an extra read or write call might be avoided.

If an error happens while polling, status will a libuv::Error. The user should not close the socket while the handle is active. If the user does that anyway, the callback may be called reporting an error status, but this is not guaranteed.

Note: Calling start() on a handle that is already active is fine. Doing so will update the events mask that is being watched for.

Note: Though DISCONNECT can be set, it is unsupported on AIX and as such will not be set on the events field in the callback.

pub fn stop(&mut self) -> Result<()>[src]

Stop polling the file descriptor, the callback will no longer be called.

Trait Implementations

impl Clone for PollHandle[src]

impl Copy for PollHandle[src]

impl From<PollHandle> for Handle[src]

impl HandleTrait for PollHandle[src]

impl ToHandle for PollHandle[src]

impl TryFrom<Handle> for PollHandle[src]

type Error = ConversionError

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.