E-MailRelay
geventhandler.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 associated file descriptor.
42 ///
43 /// If an event handler throws an exception which is caught by the
44 /// event loop then the event loop calls the associated ExceptionHandler,
45 /// if any.
46 ///
48 {
49 public:
50  enum Reason
51  {
52  reason_closed , // fin packet, clean shutdown
53  reason_down , // network down
54  reason_reset , // rst packet
55  reason_abort , // socket failed
56  reason_other // eg. oob data
57  } ;
58 
59  virtual ~EventHandler() ;
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 private:
80  void operator=( const EventHandler & ) ;
81 } ;
82 
83 #endif
Network classes.
Definition: gaddress.h:29
virtual void readEvent()
Called for a read event.
virtual void writeEvent()
Called for a write event.
A base class for classes that handle asynchronous events from the event loop.
Definition: geventhandler.h:47
static std::string str(Reason)
Returns a printable description of the other-event reason.
virtual void otherEvent(Reason)
Called for a socket-exception event or a socket-close event on windows.
virtual ~EventHandler()
Destructor.