MPD
0.20.18
|
Similar to SocketMonitor, but monitors multiple sockets. More...
#include <MultiSocketMonitor.hxx>
Public Member Functions | |
MultiSocketMonitor (EventLoop &_loop) | |
void | Reset () |
Clear the socket list and disable all EventLoop registrations. More... | |
void | InvalidateSockets () |
Invalidate the socket list. More... | |
void | AddSocket (int fd, unsigned events) |
Add one socket to the list of monitored sockets. More... | |
void | ClearSocketList () |
Remove all sockets. More... | |
template<typename E > | |
void | UpdateSocketList (E &&e) |
Update the known sockets by invoking the given function for each one; its return value is the events bit mask. More... | |
void | ReplaceSocketList (pollfd *pfds, unsigned n) |
Replace the socket list with the given file descriptors. More... | |
EventLoop & | GetEventLoop () const |
Static Public Attributes | |
static constexpr unsigned | READ = SocketMonitor::READ |
static constexpr unsigned | WRITE = SocketMonitor::WRITE |
static constexpr unsigned | ERROR = SocketMonitor::ERROR |
static constexpr unsigned | HANGUP = SocketMonitor::HANGUP |
Protected Member Functions | |
virtual std::chrono::steady_clock::duration | PrepareSockets ()=0 |
Override this method and update the socket registrations. More... | |
virtual void | DispatchSockets ()=0 |
At least one socket is ready or the timeout has expired. More... | |
Friends | |
class | SingleFD |
Similar to SocketMonitor, but monitors multiple sockets.
To use it, implement the methods PrepareSockets() and DispatchSockets(). In PrepareSockets(), use UpdateSocketList() and AddSocket(). DispatchSockets() will be called if at least one socket is ready.
Definition at line 54 of file MultiSocketMonitor.hxx.
MultiSocketMonitor::MultiSocketMonitor | ( | EventLoop & | _loop | ) |
|
inline |
Add one socket to the list of monitored sockets.
May only be called from PrepareSockets().
Definition at line 156 of file MultiSocketMonitor.hxx.
void MultiSocketMonitor::ClearSocketList | ( | ) |
Remove all sockets.
May only be called from PrepareSockets().
|
protectedpure virtual |
At least one socket is ready or the timeout has expired.
This method should be used to perform I/O.
|
inline |
Definition at line 55 of file IdleMonitor.hxx.
|
inline |
Invalidate the socket list.
A call to PrepareSockets() is scheduled which will then update the list.
Definition at line 146 of file MultiSocketMonitor.hxx.
|
protectedpure virtual |
Override this method and update the socket registrations.
To do that, call AddSocket(), ClearSocketList(), UpdateSocketList() and ReplaceSocketList().
void MultiSocketMonitor::ReplaceSocketList | ( | pollfd * | pfds, |
unsigned | n | ||
) |
Replace the socket list with the given file descriptors.
The given pollfd array will be modified by this method.
May only be called from PrepareSockets().
void MultiSocketMonitor::Reset | ( | ) |
Clear the socket list and disable all EventLoop registrations.
Run this in the EventLoop thread before destroying this object.
Later, this object can be reused and reactivated by calling InvalidateSockets().
Note that this class doesn't have a destructor which calls this method, because this would be racy and thus pointless: at the time ~MultiSocketMonitor() is called, our virtual methods have been morphed to be pure again, and in the meantime the EventLoop thread could invoke those pure methods.
|
inline |
Update the known sockets by invoking the given function for each one; its return value is the events bit mask.
A return value of 0 means the socket will be removed from the list.
May only be called from PrepareSockets().
Definition at line 176 of file MultiSocketMonitor.hxx.
|
friend |
Definition at line 97 of file MultiSocketMonitor.hxx.
|
static |
Definition at line 118 of file MultiSocketMonitor.hxx.
|
static |
Definition at line 119 of file MultiSocketMonitor.hxx.
|
static |
Definition at line 116 of file MultiSocketMonitor.hxx.
|
static |
Definition at line 117 of file MultiSocketMonitor.hxx.