20 #ifndef MPD_MULTI_SOCKET_MONITOR_HXX 21 #define MPD_MULTI_SOCKET_MONITOR_HXX 29 #include <forward_list> 64 multi(_multi), revents(0) {
72 unsigned GetEvents()
const {
76 void SetEvents(
unsigned _events) {
81 unsigned GetReturnedEvents()
const {
85 void ClearReturnedEvents() {
90 virtual bool OnSocketReady(
unsigned flags)
override {
113 std::forward_list<SingleFD> fds;
157 fds.emplace_front(*
this, fd, events);
177 for (
auto prev = fds.before_begin(), end = fds.end(),
179 i != end; i = std::next(prev)) {
180 assert(i->GetEvents() != 0);
182 unsigned events =
e(i->GetFD());
184 i->SetEvents(events);
187 fds.erase_after(prev);
226 virtual void OnTimeout() final {
231 virtual void OnIdle() final;
static constexpr unsigned WRITE
void InvalidateSockets()
Invalidate the socket list.
static constexpr unsigned READ
void AddSocket(int fd, unsigned events)
Add one socket to the list of monitored sockets.
This class monitors a timeout.
An event that runs when the EventLoop has become idle, before waiting for more events.
An event loop that polls for events on file/socket descriptors.
void UpdateSocketList(E &&e)
Update the known sockets by invoking the given function for each one; its return value is the events ...
void Schedule(unsigned flags)
void ClearSocketList()
Remove all sockets.
EventLoop & GetEventLoop() const
void Reset()
Clear the socket list and disable all EventLoop registrations.
void ReplaceSocketList(pollfd *pfds, unsigned n)
Replace the socket list with the given file descriptors.
static constexpr unsigned ERROR
virtual std::chrono::steady_clock::duration PrepareSockets()=0
Override this method and update the socket registrations.
Monitor events on a socket.
static constexpr unsigned HANGUP
MultiSocketMonitor(EventLoop &_loop)
static constexpr unsigned READ
virtual void DispatchSockets()=0
At least one socket is ready or the timeout has expired.
static constexpr unsigned WRITE
static constexpr unsigned HANGUP
Similar to SocketMonitor, but monitors multiple sockets.
static constexpr unsigned ERROR
unsigned GetScheduledFlags() const
EventLoop & GetEventLoop() const