MPD
0.20.18
|
An event loop that polls for events on file/socket descriptors. More...
#include <Loop.hxx>
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... | |
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.
EventLoop::EventLoop | ( | ) |
EventLoop::~EventLoop | ( | ) |
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.
void EventLoop::AddDeferred | ( | DeferredMonitor & | d | ) |
Schedule a call to DeferredMonitor::RunDeferred().
This method is thread-safe.
|
inline |
void EventLoop::AddIdle | ( | IdleMonitor & | i | ) |
void EventLoop::AddTimer | ( | TimeoutMonitor & | t, |
std::chrono::steady_clock::duration | d | ||
) |
void EventLoop::Break | ( | ) |
void EventLoop::CancelTimer | ( | TimeoutMonitor & | t | ) |
|
inline |
|
inlinenoexcept |
|
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.
|
inlinenoexcept |
|
inline |
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.
bool EventLoop::RemoveFD | ( | int | fd, |
SocketMonitor & | m | ||
) |
void EventLoop::RemoveIdle | ( | IdleMonitor & | i | ) |
void EventLoop::Run | ( | ) |
The main function of this class.
It will loop until Break() gets called. Can be called only once.