[−][src]Struct polling::Poller
Waits for I/O events.
Implementations
impl Poller
[src]
pub fn new() -> Result<Poller>
[src]
pub fn insert(&self, source: impl Source) -> Result<()>
[src]
Inserts a file descriptor or socket into the poller and puts it in non-blocking mode.
Before setting interest in readability or writability, the file descriptor or socket must be inserted into the poller. This method also puts it in non-blocking mode.
Don't forget to remove it when it is no longer used!
Examples
use polling::Poller; use std::net::TcpListener; let poller = Poller::new()?; let socket = TcpListener::bind("127.0.0.1:0")?; poller.insert(&socket)?;
pub fn interest(&self, source: impl Source, event: Event) -> Result<()>
[src]
Enables or disables interest in a file descriptor or socket.
A file descriptor or socket is considered readable or writable when a read or write operation on it would not block. This doesn't mean the read or write operation will succeed, it only means the operation will return immediately.
If interest is set in both readability and writability, the two kinds of events might be delivered either separately or together.
For example, interest in Event { key: 7, readable: true, writable: true }
might result in
a single Event
of the same form, or in two separate Event
s:
Event { key: 7, readable: true, writable: false }
Event { key: 7, readable: false, writable: true }
Errors
This method returns an error in the following situations:
- If
source
was not inserted into the poller. - If
key
equalsusize::MAX
because that key is reserved for internal use. - If an error is returned by the syscall.
Examples
To enable interest in all events:
poller.interest(&source, Event::all(key))?;
To enable interest in readable events and disable interest in writable events:
poller.interest(&source, Event::readable(key))?;
To disable interest in readable events and enable interest in writable events:
poller.interest(&source, Event::writable(key))?;
To disable interest in all events:
poller.interest(&source, Event::none(key))?;
pub fn remove(&self, source: impl Source) -> Result<()>
[src]
Removes a file descriptor or socket from the poller.
Unlike insert()
, this method only removes the file descriptor or
socket from the poller without putting it back into blocking mode.
Examples
use polling::Poller; use std::net::TcpListener; let poller = Poller::new()?; let socket = TcpListener::bind("127.0.0.1:0")?; poller.insert(&socket)?; poller.remove(&socket)?;
pub fn wait(
&self,
events: &mut Vec<Event>,
timeout: Option<Duration>
) -> Result<usize>
[src]
&self,
events: &mut Vec<Event>,
timeout: Option<Duration>
) -> Result<usize>
Waits for at least one I/O event and returns the number of new events.
New events will be appended to events
. If necessary, make sure to clear the Vec
before calling wait()
!
This method will return with no new events if a notification is delivered by the
notify()
method, or the timeout is reached. Sometimes it may even return with no events
spuriously.
Only one thread can wait on I/O. If another thread is already in wait()
, concurrent
calls to this method will return immediately with no new events.
If the operating system is ready to deliver a large number of events at once, this method may decide to deliver them in smaller batches.
Examples
use polling::Poller; use std::net::TcpListener; use std::time::Duration; let poller = Poller::new()?; let socket = TcpListener::bind("127.0.0.1:0")?; poller.insert(&socket)?; let mut events = Vec::new(); let n = poller.wait(&mut events, Some(Duration::from_secs(1)))?;
pub fn notify(&self) -> Result<()>
[src]
Wakes up the current or the following invocation of wait()
.
If no thread is calling wait()
right now, this method will cause the following call
to wake up immediately.
Examples
use polling::Poller; let poller = Poller::new()?; // Notify the poller. poller.notify()?; let mut events = Vec::new(); poller.wait(&mut events, None)?; // wakes up immediately assert!(events.is_empty());
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Poller
impl Send for Poller
impl Sync for Poller
impl Unpin for Poller
impl UnwindSafe for Poller
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,