20 #ifndef MPD_EVENT_LOOP_HXX 21 #define MPD_EVENT_LOOP_HXX 58 const std::chrono::steady_clock::time_point due;
63 std::chrono::steady_clock::time_point _due)
64 :due(_due), timer(_timer) {}
66 bool operator<(
const TimerRecord &other)
const {
67 return due < other.due;
70 bool IsDue(std::chrono::steady_clock::time_point _now)
const {
77 std::multiset<TimerRecord> timers;
78 std::list<IdleMonitor *> idle;
81 std::list<DeferredMonitor *> deferred;
83 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
109 PollGroup poll_group;
110 PollResult poll_result;
124 std::chrono::steady_clock::time_point
GetTime()
const {
140 return poll_group.Add(_fd, flags, &m);
146 return poll_group.Modify(_fd, flags, &m);
162 std::chrono::steady_clock::duration d);
192 void HandleDeferred();
194 virtual bool OnSocketReady(
unsigned flags)
override;
static gcc_const ThreadId Null() noexcept
gcc_pure bool IsInsideOrVirgin() const noexcept
This class monitors a timeout.
An event that runs when the EventLoop has become idle, before waiting for more events.
A low-level identification for a thread.
std::chrono::steady_clock::time_point GetTime() const
A caching wrapper for std::chrono::steady_clock::now().
void CancelTimer(TimeoutMonitor &t)
An event loop that polls for events on file/socket descriptors.
void Break()
Stop execution of this EventLoop at the next chance.
void AddIdle(IdleMonitor &i)
void RemoveIdle(IdleMonitor &i)
gcc_pure bool IsInsideOrNull() const noexcept
Like IsInside(), but also returns true if the thread has already ended (or was not started yet)...
Defer execution of an event into an EventLoop.
bool AddFD(int _fd, unsigned flags, SocketMonitor &m)
void Abandon()
Somebody has closed the socket.
bool IsInside() const noexcept
Check if this thread is the current thread.
gcc_pure bool IsNull() const noexcept
void Run()
The main function of this class.
gcc_pure bool IsInside() const noexcept
Are we currently running inside this EventLoop's thread?
Monitor events on a socket.
void AddTimer(TimeoutMonitor &t, std::chrono::steady_clock::duration d)
void AddDeferred(DeferredMonitor &d)
Schedule a call to DeferredMonitor::RunDeferred().
bool RemoveFD(int fd, SocketMonitor &m)
bool ModifyFD(int _fd, unsigned flags, SocketMonitor &m)
void RemoveDeferred(DeferredMonitor &d)
Cancel a pending call to DeferredMonitor::RunDeferred().