21#ifndef G_NET_EVENT_LOOP_H
22#define G_NET_EVENT_LOOP_H
65 G_EXCEPTION( Error ,
tx(
"event loop error") )
66 G_EXCEPTION( NoInstance ,
tx(
"no event loop instance") )
67 G_EXCEPTION( Overflow ,
tx(
"event loop overflow") )
74 static std::unique_ptr<EventLoop>
create() ;
96 virtual std::string
run() = 0 ;
103 virtual void quit(
const std::string & reason ) = 0 ;
A class that encapsulates a network socket file descriptor and an associated windows event handle.
A base class for classes that have a file descriptor and handle asynchronous events from the event lo...
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
virtual ~EventLoop()
Destructor.
virtual void dropWrite(Descriptor fd) noexcept=0
Removes the given event descriptor from the list of write sources.
virtual bool running() const =0
Returns true if called from within run().
virtual void drop(Descriptor fd) noexcept=0
Removes the given event descriptor from the event loop as the EventHandler is being destructed.
static std::unique_ptr< EventLoop > create()
A factory method which creates an instance of a derived class on the heap.
virtual void quit(const G::SignalSafe &)=0
A signal-safe overload to quit() the event loop.
static void stop(const G::SignalSafe &)
Calls quit() on instance().
virtual void dropRead(Descriptor fd) noexcept=0
Removes the given event descriptor from the list of read sources.
static EventLoop * ptr() noexcept
Returns a pointer to an instance of the class, if any.
static bool exists()
Returns true if an instance exists.
virtual void disarm(ExceptionHandler *) noexcept=0
Used to prevent the given interface from being used, typically called from the ExceptionHandler destr...
virtual void quit(const std::string &reason)=0
Causes run() to return (once the call stack has unwound).
virtual std::string run()=0
Runs the main event loop.
virtual void addWrite(Descriptor fd, EventHandler &, EventState)=0
Adds the given event source descriptor and associated handler to the write list.
static EventLoop & instance()
Returns a reference to an instance of the class, if any.
virtual void dropOther(Descriptor fd) noexcept=0
Removes the given event descriptor from the list of other-event sources.
virtual void addRead(Descriptor fd, EventHandler &, EventState)=0
Adds the given event source descriptor and associated handler to the read list.
virtual void addOther(Descriptor fd, EventHandler &, EventState)=0
Adds the given event source descriptor and associated handler to the exception list.
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket/future event...
An empty structure that is used to indicate a signal-safe, reentrant implementation.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().