#include <monitor.h>
Public Types | |
enum | { evRead = 0x0001, evWrite = 0x0002 } |
Public Member Functions | |
Monitor (std::string const &name, size_t hint) | |
Constructor. | |
virtual | ~Monitor () |
Destructor. | |
virtual void | do_events (time_t wait) |
Do events. | |
virtual bool | add (Socket *socket, int fd, unsigned int events) |
Monitors a socket. | |
virtual bool | update (Socket *socket, int fd, unsigned int events) |
Updates events monitored for a socket. | |
virtual void | remove (Socket *socket, int fd) |
Unmonitors a socket. | |
std::string const & | name () const |
Returns the name of the monitor. | |
Protected Types | |
typedef containers::VectorSP < Socket *, size_t > | sockets_list |
Type of the list of sockets. | |
Protected Member Functions | |
Socket * | get_socket (int fd) const |
Gets a socket for a given fd. | |
void | set_socket (int fd, Socket *s) |
Sets a socket for a given fd. | |
size_t | hint () const |
Returns the hint. | |
Protected Attributes | |
sockets_list | m_sockets |
The sockets list. |
The do_events(), add(), update() and remove() function must be overriden in derived classes.
sockets::Monitor::Monitor | ( | std::string const & | name, | |
size_t | hint | |||
) |
Constructor.
[in] | name | The name of the monitor. |
[in] | hint | An estimate of the number of maximum sockets that will be in use at a given time. This is NOT an actual maximum value. |
virtual void sockets::Monitor::do_events | ( | time_t | wait | ) | [inline, virtual] |
virtual bool sockets::Monitor::add | ( | Socket * | socket, | |
int | fd, | |||
unsigned int | events | |||
) | [virtual] |
Adds a socket to the monitor. This socket will be watched for the given events and receive notifications when they happen.
The default implementation calls set_socket() for the given socket/fd pair.
[in] | socket | The socket to add. |
[in] | fd | The socket file descriptor. |
[in] | events | The events to watch for initially. |
virtual bool sockets::Monitor::update | ( | Socket * | socket, | |
int | fd, | |||
unsigned int | events | |||
) | [virtual] |
Updates events monitored for a socket. The socket must have been added previously through the add() function.
The default implementation does nothing.
[in] | socket | The socket to update. |
[in] | fd | The socket file descriptor. |
[in] | events | The events to watch for. |
virtual void sockets::Monitor::remove | ( | Socket * | socket, | |
int | fd | |||
) | [virtual] |
Unmonitors a socket. The socket must have been added previously through the add() function.
The default implementation removes the socket from the internal socket list.
[in] | socket | The socket to remove. |
[in] | fd | The socket file descriptor. |