userver: engine::io::FdPoller Class Reference
Loading...
Searching...
No Matches
engine::io::FdPoller Class Referencefinal

#include <userver/engine/io/fd_poller.hpp>

Detailed Description

Low-level poller that can wait for read, write, and read/write operations on a file descriptor. It does not provide read/write operations.

Note
FdPoller is not thread safe and its methods must not be called from multiple threads simultaneously.

Definition at line 32 of file fd_poller.hpp.

Public Types

enum class  Kind {
  kRead = 1 ,
  kWrite = 2 ,
  kReadWrite = 3
}
 Operation kind to wait for. More...
 

Public Member Functions

 FdPoller (const ev::ThreadControl &control)
 
 FdPoller (const FdPoller &)=delete
 
 FdPoller (FdPoller &&)=delete
 
FdPolleroperator= (const FdPoller &)=delete
 
FdPolleroperator= (FdPoller &&)=delete
 
 operator bool () const noexcept
 The same as IsValid().
 
bool IsValid () const noexcept
 Whether the file descriptor is valid.
 
int GetFd () const noexcept
 If IsValid(), get file descriptor.
 
void Invalidate ()
 
void Reset (int fd, Kind kind)
 
std::optional< KindWait (Deadline)
 
void ResetReady () noexcept
 Reset "ready" flag for WaitAny().
 
std::optional< FdPoller::KindGetReady () noexcept
 

Member Enumeration Documentation

◆ Kind

enum class engine::io::FdPoller::Kind
strong

Operation kind to wait for.

Enumerator
kWrite 

< wait for read availability

kReadWrite 

< wait for write availability

Definition at line 35 of file fd_poller.hpp.

Constructor & Destructor Documentation

◆ FdPoller()

engine::io::FdPoller::FdPoller ( const ev::ThreadControl & control)
explicit

Constructor for FdPoller. control parameter could be obtained via engine::current_task::GetEventThread().

It is recommended to place read and write FdPoller's of the same FD to the same control for better ev threads balancing.

Member Function Documentation

◆ GetReady()

std::optional< FdPoller::Kind > engine::io::FdPoller::GetReady ( )
noexcept

Get event kind that was triggered on this poller. Resets "ready" flag.

◆ Invalidate()

void engine::io::FdPoller::Invalidate ( )

When you're done with fd, call Invalidate(). It unregisters the fd, after that you have to call close(2) by yourself. After Invalidate() you may not call Wait().

◆ Reset()

void engine::io::FdPoller::Reset ( int fd,
Kind kind )

Setup fd and kind to wait for. After Reset() you may call Wait(). FdPoller does not take the ownership of fd, you still have to close fd when you're done.

◆ Wait()

std::optional< Kind > engine::io::FdPoller::Wait ( Deadline )

Wait for an event kind that was passed in the latest Reset() call. If the operation (read/write) can already be handled, Wait() returns immediately. You have to call Reset() at least once before call to Wait().


The documentation for this class was generated from the following file: