MPD: MultiSocketMonitor Class Reference

MPD 0.20.18

Data Structures | Public Member Functions | Static Public Attributes | Protected Member Functions | Friends
MultiSocketMonitor Class Referenceabstract

Similar to SocketMonitor, but monitors multiple sockets. More...

`#include <MultiSocketMonitor.hxx>`

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

## 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

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ MultiSocketMonitor()

MultiSocketMonitor::MultiSocketMonitor | ( | EventLoop & | _loop | ) |

## Member Function Documentation

## ◆ AddSocket()

void MultiSocketMonitor::AddSocket | ( | int | fd,
|  | unsigned | events
| ) |  |
| inline

Add one socket to the list of monitored sockets.

May only be called from PrepareSockets().

Definition at line 156 of file MultiSocketMonitor.hxx.

## ◆ ClearSocketList()

void MultiSocketMonitor::ClearSocketList | ( |  | ) |

Remove all sockets.

May only be called from PrepareSockets().

## ◆ DispatchSockets()

virtual void MultiSocketMonitor::DispatchSockets | ( |  | ) |
| protectedpure virtual

At least one socket is ready or the timeout has expired.

This method should be used to perform I/O.

## ◆ GetEventLoop()

EventLoop& IdleMonitor::GetEventLoop
| inline

Definition at line 55 of file IdleMonitor.hxx.

## ◆ InvalidateSockets()

void MultiSocketMonitor::InvalidateSockets | ( |  | ) |
| 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.

## ◆ PrepareSockets()

virtual std::chrono::steady_clock::duration MultiSocketMonitor::PrepareSockets | ( |  | ) |
| protectedpure virtual

Override this method and update the socket registrations.

To do that, call AddSocket(), ClearSocketList(), UpdateSocketList() and ReplaceSocketList().

Returns
  timeout or a negative value for no timeout

## ◆ 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().

## ◆ Reset()

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.

## ◆ UpdateSocketList()

template<typename E >

void MultiSocketMonitor::UpdateSocketList | ( | E && | e | ) |
| 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.

## Friends And Related Function Documentation

## ◆ SingleFD

friend class SingleFD
| friend

Definition at line 97 of file MultiSocketMonitor.hxx.

## Field Documentation

## ◆ ERROR

constexpr unsigned MultiSocketMonitor::ERROR = SocketMonitor::ERROR
| static

Definition at line 118 of file MultiSocketMonitor.hxx.

## ◆ HANGUP

constexpr unsigned MultiSocketMonitor::HANGUP = SocketMonitor::HANGUP
| static

Definition at line 119 of file MultiSocketMonitor.hxx.

## ◆ READ

constexpr unsigned MultiSocketMonitor::READ = SocketMonitor::READ
| static

Definition at line 116 of file MultiSocketMonitor.hxx.

## ◆ WRITE

constexpr unsigned MultiSocketMonitor::WRITE = SocketMonitor::WRITE
| static

Definition at line 117 of file MultiSocketMonitor.hxx.

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

- event/MultiSocketMonitor.hxx