#include <reactor.h>
Public Member Functions | |
virtual | ~reactor () |
reactor () | |
void | process (bool block=false) |
void | run () |
void | for_each_endpoint (endpoint_functor &func) |
void | add_endpoint (const endpoint::pointer &ep) |
void | register_at_job (const time_value &when, at_job *jp) |
void | register_at_job_delta (const time_value &when, at_job *jp) |
void | unregister_at_job (at_job *jp) |
bool | still_have_work_to_do () const |
Private Types | |
typedef std::list < endpoint::pointer > | endpoints_t |
Private Member Functions | |
void | fatal_error (const char *fmt,...) FORMAT_PRINTF(2 |
void void | fatal_error_v (const char *fmt, va_list ap) FORMAT_PRINTF(2 |
void void void | kill_suicidal_endpoints () |
reactor (const reactor &) | |
reactor & | operator= (const reactor &) |
Private Attributes | |
endpoints_t | endpoints |
at_service | at |
The plumbing::reactor class is used to represent an endpoint manager which dispatches to the appropriate endpoint when some file descriptor activity has been detected for them.
The endpoints are completely abstract. They could be a socket listening for new connections, they could be server processes handling client requests, they could be clients handling asynchronous events, or they could be character devices like serial ports.
In particular, if you want your server to listen for connections on a particular port, derive a new class from plumbing::endpoint_listener and define the get_default_port and endpoint_factory methods. The add this listener to the reactor via the add_endpoint method. Fram that point, new connection handling is automatic.
Definition at line 49 of file reactor.h.
typedef std::list<endpoint::pointer> plumbing::reactor::endpoints_t [private] |
plumbing::reactor::~reactor | ( | ) | [virtual] |
The destructor.
Definition at line 30 of file reactor.cc.
plumbing::reactor::reactor | ( | ) |
The default constructor.
Definition at line 52 of file reactor.cc.
plumbing::reactor::reactor | ( | const reactor & | ) | [private] |
The copy constructor. Do not use.
void plumbing::reactor::add_endpoint | ( | const endpoint::pointer & | ep | ) |
The add_endpoint method is used to add another endpoint to those being managed by this reactor. When an endpoint wants to be destroyed, it shall call its kill_Pme_now method, and the reactor will destroy the pointer (and indirectly the object) at the top of its event loop.
ep | The endpoint to be managed by this reactor. It shall be dynamically allocated via operator new, via a class create method. It is recommended that this should be the only pointer to the object once it has been created, otherwise its destructor may not be called for some time, potentially leaking resources such as memory and file descriptors. |
Definition at line 249 of file reactor.cc.
void plumbing::reactor::fatal_error | ( | const char * | fmt, | |
... | ||||
) | [private] |
The fatal_error method is used to report fatal errors.
fmt | The format string describing the rest of the arguments. See printf(3) for more information. |
Definition at line 36 of file reactor.cc.
void plumbing::reactor::fatal_error_v | ( | const char * | fmt, | |
va_list | ap | |||
) | [private] |
The fatal_error_v method is used to report fatal errors, but it gets its arguments form the given location
fmt | The format string describing the rest of the arguments. See vprintf(3) for more information. | |
ap | pointer to the arguments |
Definition at line 46 of file reactor.cc.
void plumbing::reactor::for_each_endpoint | ( | endpoint_functor & | func | ) |
The for_each_endpoint method is used to apply the given functor to each of the connected clients (as presesented by each endpoint object; they could be servers, or clients, or devices, etc).
func | The operatoin to be performed. |
Definition at line 256 of file reactor.cc.
void plumbing::reactor::kill_suicidal_endpoints | ( | ) | [private] |
The kill_suicidal_endpoints method is called by the process method to clean up endpoints that are finished.
Definition at line 67 of file reactor.cc.
The assignment operator. Do not use.
void plumbing::reactor::process | ( | bool | block = false |
) |
The process method is used to see if any of the if there are any incoming connections, or if any of the current endpoints have input to process.
block | whether or not we should block |
Definition at line 86 of file reactor.cc.
void plumbing::reactor::register_at_job | ( | const time_value & | when, | |
at_job * | jp | |||
) | [inline] |
void plumbing::reactor::register_at_job_delta | ( | const time_value & | when, | |
at_job * | jp | |||
) | [inline] |
void plumbing::reactor::run | ( | ) | [inline] |
bool plumbing::reactor::still_have_work_to_do | ( | ) | const [inline] |
void plumbing::reactor::unregister_at_job | ( | at_job * | jp | ) | [inline] |
at_service plumbing::reactor::at [private] |
endpoints_t plumbing::reactor::endpoints [private] |