- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gheapclient.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // gheapclient.cpp
19 //
20
21 #include "gdef.h"
22 #include "gnet.h"
23 #include "gheapclient.h"
24 #include "gdebug.h"
25
26 GNet::HeapClient::HeapClient( const ResolverInfo & remote_info ,
27 const Address & local_interface , bool privileged , bool sync_dns ,
28 unsigned int secure_connection_timeout ) :
29 SimpleClient(remote_info,local_interface,privileged,sync_dns,secure_connection_timeout) ,
30 m_connect_timer(*this,&HeapClient::onConnectionTimeout,*this) ,
31 m_delete_timer(*this,&HeapClient::onDeletionTimeout,*this)
32 {
33 m_connect_timer.startTimer( 0U ) ;
34 }
35
36 GNet::HeapClient::~HeapClient()
37 {
38 }
39
40 void GNet::HeapClient::onConnectionTimeout()
41 {
42 onConnecting() ;
43 connect() ;
44 }
45
46 void GNet::HeapClient::onDeletionTimeout()
47 {
48 try
49 {
50 doDeleteThis() ;
51 }
52 catch( std::exception & e ) // never gets here
53 {
54 G_ERROR( "HeapClientTimer::onTimeout: exception: " << e.what() ) ;
55 }
56 }
57
58 void GNet::HeapClient::doDeleteForExit()
59 {
60 delete this ;
61 }
62
63 void GNet::HeapClient::doDelete( const std::string & reason )
64 {
65 m_connect_timer.cancelTimer() ;
66 m_delete_timer.startTimer( 0U ) ; // before the callbacks, in case they throw
67 onDeleteImp( reason , canRetry(reason) ) ; // first -- for 'internal' library classes
68 onDelete( reason , canRetry(reason) ) ; // second -- for 'external' client classes
69 }
70
71 void GNet::HeapClient::doDeleteThis()
72 {
73 delete this ;
74 }
75
76 void GNet::HeapClient::onException( std::exception & e )
77 {
78 G_WARNING( "GNet::HeapClient::onException: exception: " << e.what() ) ;
79 doDelete( e.what() ) ;
80 }
81
82 void GNet::HeapClient::onDeleteImp( const std::string & , bool )
83 {
84 }
85
86 void GNet::HeapClient::onConnecting()
87 {
88 }
89
GNet::HeapClient::~HeapClient
virtual ~HeapClient()
Destructor.
Definition: gheapclient.cpp:36
GNet::SimpleClient
A class for making an outgoing connection to a remote server, with support for socket-level protocols...
Definition: gsimpleclient.h:81
GNet::HeapClient::onException
virtual void onException(std::exception &)
Final override from GNet::EventHandler.
Definition: gheapclient.cpp:76
GNet::Address
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
GNet::ResolverInfo
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
GNet::HeapClient::doDelete
void doDelete(const std::string &reason)
Calls onDelete() and then does a delayed "delete this".
Definition: gheapclient.cpp:63
G_ERROR
#define G_ERROR(expr)
Definition: glog.h:108
GNet::HeapClient
A SimpleClient class for client objects that manage their own lifetime on the heap.
Definition: gheapclient.h:54
GNet::HeapClient::onDeleteImp
virtual void onDeleteImp(const std::string &reason, bool can_retry)
An alternative to onDelete() for private implementation classes.
Definition: gheapclient.cpp:82
GNet::HeapClient::doDeleteForExit
void doDeleteForExit()
A destructor method that may be called at program termination when the normal doDelete() mechanism ha...
Definition: gheapclient.cpp:58
GNet::HeapClient::HeapClient
HeapClient(const ResolverInfo &remote_info, const Address &local_interface=Address(0U), bool privileged=false, bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U)
Constructor.
Definition: gheapclient.cpp:26
gheapclient.h
GNet::HeapClient::onConnecting
virtual void onConnecting()
Called just before the connection is initiated.
Definition: gheapclient.cpp:86
G_WARNING
#define G_WARNING(expr)
Definition: glog.h:107
gdebug.h