E-MailRelay
geventhandler.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 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.cpp
19///
20
21#include "gdef.h"
22#include "geventhandler.h"
23#include "gexception.h"
24#include "geventloop.h"
25#include "glog.h"
26
28= default ;
29
31{
32 static_assert( noexcept(EventLoop::ptr()) , "" ) ;
33 static_assert( noexcept(EventLoop::ptr()->drop(GNet::Descriptor())) , "" ) ;
34 EventLoop * event_loop = EventLoop::ptr() ;
35 if( event_loop != nullptr )
36 event_loop->drop( m_fd ) ;
37}
38
40{
41 G_DEBUG( "GNet::EventHandler::readEvent: no override" ) ;
42}
43
45{
46 G_DEBUG( "GNet::EventHandler::writeEvent: no override" ) ;
47}
48
49void GNet::EventHandler::otherEvent( EventHandler::Reason reason )
50{
51 throw G::Exception( "socket disconnect event" , str(reason) ) ;
52}
53
54std::string GNet::EventHandler::str( EventHandler::Reason reason )
55{
56 if( reason == EventHandler::Reason::failed ) return "connection failed" ;
57 if( reason == EventHandler::Reason::closed ) return "closed" ;
58 if( reason == EventHandler::Reason::down ) return "network down" ;
59 if( reason == EventHandler::Reason::reset ) return "connection reset by peer" ;
60 if( reason == EventHandler::Reason::abort ) return "connection aborted" ;
61 return {} ;
62}
63
A class that encapsulates a network socket file descriptor and an associated windows event handle.
Definition: gdescriptor.h:37
virtual void readEvent()
Called for a read event.
virtual void writeEvent()
Called for a write event.
virtual ~EventHandler()
Destructor.
EventHandler()
Constructor.
virtual void otherEvent(Reason)
Called for a socket-exception event, or a socket-close event on windows.
static std::string str(Reason)
Returns a printable description of the other-event reason.
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
Definition: geventloop.h:63
virtual void drop(Descriptor fd) noexcept=0
Removes the given event descriptor from the event loop as the EventHandler is being destructed.
static EventLoop * ptr() noexcept
Returns a pointer to an instance of the class, if any.
Definition: geventloop.cpp:40
A general-purpose exception class derived from std::exception and containing an error message.
Definition: gexception.h:64