plumbing::reactor Class Reference
#include <reactor.h>
Detailed Description
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.
Member Typedef Documentation
Constructor & Destructor Documentation
virtual plumbing::reactor::~reactor |
( |
|
) |
[virtual] |
plumbing::reactor::reactor |
( |
|
) |
|
plumbing::reactor::reactor |
( |
const reactor & |
|
) |
[private] |
The copy constructor. Do not use.
Member Function Documentation
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.
- Parameters:
-
| 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. |
void plumbing::reactor::fatal_error |
( |
const char * |
fmt, |
|
|
|
... | |
|
) |
| | [private] |
The fatal_error method is used to report fatal errors.
- Parameters:
-
| fmt | The format string describing the rest of the arguments. See printf(3) for more information. |
void 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
- Parameters:
-
| fmt | The format string describing the rest of the arguments. See vprintf(3) for more information. |
| ap | pointer to the arguments |
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).
- Parameters:
-
| func | The operatoin to be performed. |
void void 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.
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.
- Parameters:
-
| block | whether or not we should block |
- Note:
- This method will only block if a child endpoint blocks.
void plumbing::reactor::register_at_job |
( |
const time_value & |
when, |
|
|
at_job * |
jp | |
|
) |
| | [inline] |
The register_at_job method is used to add a jobs to the queue of jobs waiting to run.
- Parameters:
-
| when | The time the job is to be called. |
| jp | The job to be queued. |
Definition at line 123 of file reactor.h.
void plumbing::reactor::register_at_job_delta |
( |
const time_value & |
when, |
|
|
at_job * |
jp | |
|
) |
| | [inline] |
The The register_at_job_delta method is used to add a jobs to the queue of jobs waiting to run.
- Parameters:
-
| when | How many seconds into the future the job is to be called. |
| jp | The job to be queued. |
Definition at line 138 of file reactor.h.
void plumbing::reactor::run |
( |
|
) |
[inline] |
The run method is used to process all file descriptor activity. This method blocks until all connections are closed.
Definition at line 79 of file reactor.h.
bool plumbing::reactor::still_have_work_to_do |
( |
|
) |
const [inline] |
The still_have_work_to_do method is used to determine whether or not there are any endpoints left to process.
Definition at line 160 of file reactor.h.
void plumbing::reactor::unregister_at_job |
( |
at_job * |
jp |
) |
[inline] |
The unregister_at_job method is used to remove a job from the queue of jobs waiting to run.
- Parameters:
-
| jp | The job to be de-queued. |
Definition at line 151 of file reactor.h.
Field Documentation
The at instance variable is used to remember and manage all of the time-delayed jobs which need to be executed.
Definition at line 175 of file reactor.h.
The endpoints instance variable is used to remember the currently instantiated endpoints of this reactor.
Definition at line 169 of file reactor.h.
The documentation for this class was generated from the following file: