E-MailRelay
Public Types | Public Member Functions | Static Public Member Functions | List of all members
GNet::EventHandler Class Reference

A base class for classes that have a file descriptor and handle asynchronous events from the event loop. More...

#include <geventhandler.h>

+ Inheritance diagram for GNet::EventHandler:

Public Types

enum class  Reason {
  failed , closed , down , reset ,
  abort , other
}
 

Public Member Functions

 EventHandler ()
 Constructor.
 
virtual ~EventHandler ()
 Destructor. More...
 
virtual void readEvent ()
 Called for a read event. More...
 
virtual void writeEvent ()
 Called for a write event. More...
 
virtual void otherEvent (Reason)
 Called for a socket-exception event, or a socket-close event on windows. More...
 
void setDescriptor (Descriptor) noexcept
 File descriptor setter. Used by the event loop. More...
 
Descriptor descriptor () const noexcept
 File descriptor getter. Used by the event loop. More...
 
 EventHandler (const EventHandler &)=delete
 
 EventHandler (EventHandler &&)=delete
 
EventHandleroperator= (const EventHandler &)=delete
 
EventHandleroperator= (EventHandler &&)=delete
 

Static Public Member Functions

static std::string str (Reason)
 Returns a printable description of the other-event reason. More...
 

Detailed Description

A base class for classes that have a file descriptor and handle asynchronous events from the event loop.

The event handler virtual methods are called when an event is detected on the associated file descriptor.

The EventEmitter class ensures that if an exception is thrown out of an event handler it is caught and delivered to an associated ExceptionHandler interface (if any).

Definition at line 47 of file geventhandler.h.

Member Enumeration Documentation

◆ Reason

enum class GNet::EventHandler::Reason
strong

Definition at line 50 of file geventhandler.h.

Constructor & Destructor Documentation

◆ ~EventHandler()

GNet::EventHandler::~EventHandler ( )
virtual

Destructor.

Definition at line 30 of file geventhandler.cpp.

Member Function Documentation

◆ descriptor()

GNet::Descriptor GNet::EventHandler::descriptor ( ) const
inlinenoexcept

File descriptor getter. Used by the event loop.

Definition at line 107 of file geventhandler.h.

◆ otherEvent()

void GNet::EventHandler::otherEvent ( EventHandler::Reason  reason)
virtual

Called for a socket-exception event, or a socket-close event on windows.

Overridable. The default implementation throws an exception.

Definition at line 49 of file geventhandler.cpp.

◆ readEvent()

void GNet::EventHandler::readEvent ( )
virtual

Called for a read event.

Overridable. The default implementation does nothing. The descriptor might not be valid() if a non-socket event on windows.

Definition at line 39 of file geventhandler.cpp.

◆ setDescriptor()

void GNet::EventHandler::setDescriptor ( Descriptor  fd)
inlinenoexcept

File descriptor setter. Used by the event loop.

Definition at line 101 of file geventhandler.h.

◆ str()

std::string GNet::EventHandler::str ( EventHandler::Reason  reason)
static

Returns a printable description of the other-event reason.

Definition at line 54 of file geventhandler.cpp.

◆ writeEvent()

void GNet::EventHandler::writeEvent ( )
virtual

Called for a write event.

Overrideable. The default implementation does nothing.

Definition at line 44 of file geventhandler.cpp.


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