|
E-MailRelay
|
A class that maps from a file descriptor to an event handler, used in the implemention of classes derived from GNet::EventLoop. More...
#include <geventhandlerlist.h>
Classes | |
| struct | Iterator |
| An iterator for GNet::EventHandlerList. More... | |
| struct | Lock |
| A raii class to lock and unlock GNet::EventHandlerList. More... | |
| struct | Value |
| A tuple for GNet::EventHandlerList. More... | |
Public Member Functions | |
| EventHandlerList (const std::string &type) | |
| Constructor. More... | |
| void | add (Descriptor fd, EventHandler *handler, ExceptionHandler *) |
| Adds a file-descriptor/handler tuple to the list. | |
| void | remove (Descriptor fd) |
| Removes a file-descriptor from the list. | |
| Iterator | find (Descriptor fd) const |
| Finds an entry in the list. More... | |
| bool | contains (Descriptor fd) const |
| Returns true if the list, taking account of any pending changes, contains the given descriptor. More... | |
| void | lock () |
| To be called at the start of an begin()/end() iteration if the list might change during the iteration. More... | |
| bool | unlock () |
| Called at the end of a begin()/end() iteration to match a call to lock(). More... | |
| Iterator | begin () const |
| Returns a forward iterator. Use lock() before iterating. | |
| Iterator | end () const |
| Returns an end iterator. | |
| void | disarm (ExceptionHandler *) |
| Resets any matching ExceptionHandler pointers. | |
A class that maps from a file descriptor to an event handler, used in the implemention of classes derived from GNet::EventLoop.
If an event handler is removed from the list while the list is being iterated over then the relevant pointer is reset without affecting the iteration. The unlock() method does garbage collection once the iteration is complete.
If an event handler is added to the list while the list is being iterated over then it is added to a pending-list. The pending list is added to the main list by unlock() once the iteration is complete.
Each event handler can also have an associated exception handler, typically a more long-lived object that has the event handler as a sub-object. The exception handler is invoked if the event handler throws. This is safe even if the exception handler object is destroyed by the exception because the exception handler base-class destructor uses the disarm() mechanism.
Note that the Descriptor class is actually in two parts for Windows: a socket handle (file descriptor) and an event-object handle. The event handler list is keyed by the full Descriptor object rather than just the socket handle and this allows it to contain event-handling objects that are not sockets. See GNet::FutureEvent.
Definition at line 63 of file geventhandlerlist.h.
|
explicit |
Constructor.
The type parameter (eg. "read") is used only in debugging messages.
Definition at line 38 of file geventhandlerlist.cpp.
| bool GNet::EventHandlerList::contains | ( | Descriptor | fd | ) | const |
Returns true if the list, taking account of any pending changes, contains the given descriptor.
Definition at line 122 of file geventhandlerlist.cpp.
| GNet::EventHandlerList::Iterator GNet::EventHandlerList::find | ( | Descriptor | fd | ) | const |
| void GNet::EventHandlerList::lock | ( | ) |
To be called at the start of an begin()/end() iteration if the list might change during the iteration.
Must be paired with unlock().
Definition at line 131 of file geventhandlerlist.cpp.
| bool GNet::EventHandlerList::unlock | ( | ) |
Called at the end of a begin()/end() iteration to match a call to lock().
Does garbage collection. Returns true if anything might have changed.
Definition at line 136 of file geventhandlerlist.cpp.
1.8.9.1