E-MailRelay

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
GNet::EventLoop Class Referenceabstract

An abstract base class for a singleton that keeps track of open sockets and their associated handlers. More...

`#include <geventloop.h>`

Inheritance diagram for GNet::EventLoop:

## Public Member Functions
virtual | ~EventLoop ()
| Destructor. More...
virtual std::string | run ()=0
| Runs the main event loop. More...
virtual bool | running () const =0
| Returns true if called from within run().
virtual void | quit (const std::string &reason)=0
| Causes run() to return (once the call stack has unwound). More...
virtual void | quit (const G::SignalSafe &)=0
| A signal-safe overload to quit() the event loop.
virtual void | addRead (Descriptor fd, EventHandler &, ExceptionSink)=0
| Adds the given event source descriptor and associated handler to the read list. More...
virtual void | addWrite (Descriptor fd, EventHandler &, ExceptionSink)=0
| Adds the given event source descriptor and associated handler to the write list. More...
virtual void | addOther (Descriptor fd, EventHandler &, ExceptionSink)=0
| Adds the given event source descriptor and associated handler to the exception list. More...
virtual void | dropRead (Descriptor fd) noexcept=0
| Removes the given event source descriptor from the list of read sources. More...
virtual void | dropWrite (Descriptor fd) noexcept=0
| Removes the given event source descriptor from the list of write sources. More...
virtual void | dropOther (Descriptor fd) noexcept=0
| Removes the given event source descriptor from the list of exception sources. More...
virtual void | disarm (ExceptionHandler *) noexcept=0
| Used to prevent the given interface from being used, typically called from the ExceptionHandler destructor.
| EventLoop (const EventLoop &)=delete
| EventLoop (EventLoop &&)=delete
void | operator= (const EventLoop &)=delete
void | operator= (EventLoop &&)=delete

## Static Public Member Functions
static std::unique_ptr< EventLoop > | create ()
| A factory method which creates an instance of a derived class on the heap. More...
static EventLoop & | instance ()
| Returns a reference to an instance of the class, if any. More...
static EventLoop * | ptr () noexcept
| Returns a pointer to an instance of the class, if any. More...
static bool | exists ()
| Returns true if an instance exists. More...
static void | stop (const G::SignalSafe &)
| Calls quit() on instance(). More...

## Protected Member Functions
| EventLoop ()
| Constructor. More...

## Detailed Description

An abstract base class for a singleton that keeps track of open sockets and their associated handlers.

Derived classes are used to implement different event loops, such as select() or WaitForMultipleObjects().

In practice sockets should be added and removed from the class by calling GNet::Socket::addReadHandler() and friends rather than by calling EventLoop::addRead() etc. so that the event handle is passed correctly when running on windows.

The class has a static member for finding an instance, but instances are not created automatically.

Definition at line 52 of file geventloop.h.

## Constructor & Destructor Documentation

## ◆ EventLoop()

GNet::EventLoop::EventLoop | ( |  | ) |
| protected

Constructor.

Definition at line 28 of file geventloop.cpp.

## ◆ ~EventLoop()

GNet::EventLoop::~EventLoop | ( |  | ) |
| virtual

Destructor.

Definition at line 36 of file geventloop.cpp.

## Member Function Documentation

## ◆ addOther()

virtual void GNet::EventLoop::addOther | ( | Descriptor | fd,
|  | EventHandler & | ,
|  | ExceptionSink |
| ) |  |
| pure virtual

Adds the given event source descriptor and associated handler to the exception list.

See also Socket::addOtherHandler().

## ◆ addRead()

virtual void GNet::EventLoop::addRead | ( | Descriptor | fd,
|  | EventHandler & | ,
|  | ExceptionSink |
| ) |  |
| pure virtual

Adds the given event source descriptor and associated handler to the read list.

See also Socket::addReadHandler().

## ◆ addWrite()

virtual void GNet::EventLoop::addWrite | ( | Descriptor | fd,
|  | EventHandler & | ,
|  | ExceptionSink |
| ) |  |
| pure virtual

Adds the given event source descriptor and associated handler to the write list.

See also Socket::addWriteHandler().

## ◆ create()

std::unique_ptr< GNet::EventLoop > GNet::EventLoop::create | ( |  | ) |
| static

A factory method which creates an instance of a derived class on the heap.

Throws on error.

Definition at line 192 of file geventloop_select.cpp.

## ◆ dropOther()

virtual void GNet::EventLoop::dropOther | ( | Descriptor | fd | ) |
| pure virtual noexcept

Removes the given event source descriptor from the list of exception sources.

See also Socket::dropOtherHandler().

## ◆ dropRead()

virtual void GNet::EventLoop::dropRead | ( | Descriptor | fd | ) |
| pure virtual noexcept

Removes the given event source descriptor from the list of read sources.

See also Socket::dropReadHandler().

## ◆ dropWrite()

virtual void GNet::EventLoop::dropWrite | ( | Descriptor | fd | ) |
| pure virtual noexcept

Removes the given event source descriptor from the list of write sources.

See also Socket::dropWriteHandler().

## ◆ exists()

bool GNet::EventLoop::exists | ( |  | ) |
| static

Returns true if an instance exists.

Definition at line 54 of file geventloop.cpp.

## ◆ instance()

GNet::EventLoop & GNet::EventLoop::instance | ( |  | ) |
| static

Returns a reference to an instance of the class, if any.

Throws if none. Does not do any instantiation itself.

Definition at line 47 of file geventloop.cpp.

## ◆ ptr()

GNet::EventLoop * GNet::EventLoop::ptr | ( |  | ) |
| static noexcept

Returns a pointer to an instance of the class, if any.

Returns the null pointer if none.

Definition at line 42 of file geventloop.cpp.

## ◆ quit()

virtual void GNet::EventLoop::quit | ( | const std::string & | reason | ) |
| pure virtual

Causes run() to return (once the call stack has unwound).

If there are multiple quit()s before run() returns then the latest reason is used.

## ◆ run()

virtual std::string GNet::EventLoop::run | ( |  | ) |
| pure virtual

Runs the main event loop.

Returns a quit() reason, if any.

## ◆ stop()

void GNet::EventLoop::stop | ( | const G::SignalSafe & | signal_safe | ) |
| static

Calls quit() on instance().

Definition at line 59 of file geventloop.cpp.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/geventloop.h
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/geventloop.cpp
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/geventloop_select.cpp