MPD  0.20.18
Data Structures | Public Member Functions
EventLoop Class Referencefinal

An event loop that polls for events on file/socket descriptors. More...

#include <Loop.hxx>

Inheritance diagram for EventLoop:
[legend]
Collaboration diagram for EventLoop:
[legend]

Public Member Functions

 EventLoop ()
 
 ~EventLoop ()
 
std::chrono::steady_clock::time_point GetTime () const
 A caching wrapper for std::chrono::steady_clock::now(). More...
 
void Break ()
 Stop execution of this EventLoop at the next chance. More...
 
bool AddFD (int _fd, unsigned flags, SocketMonitor &m)
 
bool ModifyFD (int _fd, unsigned flags, SocketMonitor &m)
 
bool Abandon (int fd, SocketMonitor &m)
 Remove the given SocketMonitor after the file descriptor has been closed. More...
 
bool RemoveFD (int fd, SocketMonitor &m)
 
void AddIdle (IdleMonitor &i)
 
void RemoveIdle (IdleMonitor &i)
 
void AddTimer (TimeoutMonitor &t, std::chrono::steady_clock::duration d)
 
void CancelTimer (TimeoutMonitor &t)
 
void AddDeferred (DeferredMonitor &d)
 Schedule a call to DeferredMonitor::RunDeferred(). More...
 
void RemoveDeferred (DeferredMonitor &d)
 Cancel a pending call to DeferredMonitor::RunDeferred(). More...
 
void Run ()
 The main function of this class. More...
 
gcc_pure bool IsInside () const noexcept
 Are we currently running inside this EventLoop's thread? More...
 
gcc_pure bool IsInsideOrVirgin () const noexcept
 
gcc_pure bool IsInsideOrNull () const noexcept
 Like IsInside(), but also returns true if the thread has already ended (or was not started yet). More...
 

Detailed Description

An event loop that polls for events on file/socket descriptors.

This class is not thread-safe, all methods must be called from the thread that runs it, except where explicitly documented as thread-safe.

See also
SocketMonitor, MultiSocketMonitor, TimeoutMonitor, IdleMonitor

Definition at line 52 of file Loop.hxx.

Constructor & Destructor Documentation

◆ EventLoop()

EventLoop::EventLoop ( )

◆ ~EventLoop()

EventLoop::~EventLoop ( )

Member Function Documentation

◆ Abandon()

bool EventLoop::Abandon ( int  fd,
SocketMonitor m 
)

Remove the given SocketMonitor after the file descriptor has been closed.

This is like RemoveFD(), but does not attempt to use #EPOLL_CTL_DEL.

◆ AddDeferred()

void EventLoop::AddDeferred ( DeferredMonitor d)

Schedule a call to DeferredMonitor::RunDeferred().

This method is thread-safe.

◆ AddFD()

bool EventLoop::AddFD ( int  _fd,
unsigned  flags,
SocketMonitor m 
)
inline

Definition at line 138 of file Loop.hxx.

◆ AddIdle()

void EventLoop::AddIdle ( IdleMonitor i)

◆ AddTimer()

void EventLoop::AddTimer ( TimeoutMonitor t,
std::chrono::steady_clock::duration  d 
)

◆ Break()

void EventLoop::Break ( )

Stop execution of this EventLoop at the next chance.

This method is thread-safe and non-blocking: after returning, it is not guaranteed that the EventLoop has really stopped.

◆ CancelTimer()

void EventLoop::CancelTimer ( TimeoutMonitor t)

◆ GetTime()

std::chrono::steady_clock::time_point EventLoop::GetTime ( ) const
inline

A caching wrapper for std::chrono::steady_clock::now().

Definition at line 125 of file Loop.hxx.

◆ IsInside()

gcc_pure bool EventLoop::IsInside ( ) const
inlinenoexcept

Are we currently running inside this EventLoop's thread?

Definition at line 203 of file Loop.hxx.

◆ IsInsideOrNull()

gcc_pure bool EventLoop::IsInsideOrNull ( ) const
inlinenoexcept

Like IsInside(), but also returns true if the thread has already ended (or was not started yet).

This is useful for code which may run during startup or shutdown, when events are not yet/anymore handled.

Definition at line 223 of file Loop.hxx.

◆ IsInsideOrVirgin()

gcc_pure bool EventLoop::IsInsideOrVirgin ( ) const
inlinenoexcept

Definition at line 211 of file Loop.hxx.

◆ ModifyFD()

bool EventLoop::ModifyFD ( int  _fd,
unsigned  flags,
SocketMonitor m 
)
inline

Definition at line 144 of file Loop.hxx.

◆ RemoveDeferred()

void EventLoop::RemoveDeferred ( DeferredMonitor d)

Cancel a pending call to DeferredMonitor::RunDeferred().

However after returning, the call may still be running.

This method is thread-safe.

◆ RemoveFD()

bool EventLoop::RemoveFD ( int  fd,
SocketMonitor m 
)

◆ RemoveIdle()

void EventLoop::RemoveIdle ( IdleMonitor i)

◆ Run()

void EventLoop::Run ( )

The main function of this class.

It will loop until Break() gets called. Can be called only once.


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