E-MailRelay

geventhandler.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file geventhandler.h
19///
20
21#ifndef G_NET_EVENT_HANDLER_H
22#define G_NET_EVENT_HANDLER_H
23
24#include "gdef.h"
25#include "gdatetime.h"
26#include "gexceptionhandler.h"
27#include "gdescriptor.h"
28#include <vector>
29#include <string>
30
31 namespace GNet
32{
33 class EventHandler ;
34}
35
36//| \class GNet::EventHandler
37/// A base class for classes that handle asynchronous events from the
38/// event loop.
39///
40/// An event handler object has its virtual methods called when an
41/// event is detected on the relevant file descriptor.
42///
43/// The EventHandlerList class ensures that if an exception is thrown
44/// out of an event handler it is caught and delivered to an associated
45/// ExceptionHandler interface (if any).
46///
47 class GNet::EventHandler
48{
49 public:
50 enum class Reason
51 {
52 closed , // fin packet, clean shutdown
53 down , // network down
54 reset , // rst packet
55 abort , // socket failed
56 other // eg. oob data
57 } ;
58
59 virtual ~EventHandler() = default ;
60 ///< Destructor.
61
62 virtual void readEvent() ;
63 ///< Called for a read event. Overridable. The default
64 ///< implementation does nothing.
65
66 virtual void writeEvent() ;
67 ///< Called for a write event. Overrideable. The default
68 ///< implementation does nothing.
69
70 virtual void otherEvent( Reason ) ;
71 ///< Called for a socket-exception event, or a socket-close
72 ///< event on windows. Overridable. The default
73 ///< implementation throws an exception.
74
75 static std::string str( Reason ) ;
76 ///< Returns a printable description of the other-event
77 ///< reason.
78} ;
79
80#endif
GNet::EventHandler
A base class for classes that handle asynchronous events from the event loop.
Definition: geventhandler.h:48
GNet::EventHandler::readEvent
virtual void readEvent()
Called for a read event.
Definition: geventhandler.cpp:26
GNet::EventHandler::writeEvent
virtual void writeEvent()
Called for a write event.
Definition: geventhandler.cpp:31
GNet::EventHandler::~EventHandler
virtual ~EventHandler()=default
Destructor.
GNet::EventHandler::otherEvent
virtual void otherEvent(Reason)
Called for a socket-exception event, or a socket-close event on windows.
Definition: geventhandler.cpp:36
GNet::EventHandler::str
static std::string str(Reason)
Returns a printable description of the other-event reason.
Definition: geventhandler.cpp:46
gdatetime.h
gdescriptor.h
gexceptionhandler.h
GNet
Network classes.
Definition: gdef.h:1115