gheapclient.h
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 // ===
20 
21 #ifndef G_HEAP_CLIENT_H
22 #define G_HEAP_CLIENT_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gsimpleclient.h"
27 #include "gtimer.h"
28 
30 namespace GNet
31 {
32  class HeapClient ;
33 }
34 
55 {
56 public:
57  explicit HeapClient( const ResolverInfo & remote_info ,
58  const Address & local_interface = Address(0U) , bool privileged = false ,
59  bool sync_dns = synchronousDnsDefault() ,
60  unsigned int secure_connection_timeout = 0U ) ;
63 
64  void doDelete( const std::string & reason ) ;
66 
67  virtual void onException( std::exception & ) ;
69 
70  void doDeleteForExit() ;
74 
75 protected:
76  virtual ~HeapClient() ;
78 
79  virtual void onDelete( const std::string & reason , bool can_retry ) = 0 ;
81 
82  virtual void onDeleteImp( const std::string & reason , bool can_retry ) ;
86 
87  virtual void onConnecting() ;
90 
91 private:
92  HeapClient( const HeapClient& ) ; // not implemented
93  void operator=( const HeapClient& ) ; // not implemented
94  void onConnectionTimeout() ;
95  void onDeletionTimeout() ;
96  void doDeleteThis() ;
97 
98 private:
99  GNet::Timer<HeapClient> m_connect_timer ;
100  GNet::Timer<HeapClient> m_delete_timer ;
101 } ;
102 
103 #endif
virtual void onDelete(const std::string &reason, bool can_retry)=0
Called just before deletion.
virtual ~HeapClient()
Destructor.
Definition: gheapclient.cpp:36
A class for making an outgoing connection to a remote server, with support for socket-level protocols...
Definition: gsimpleclient.h:81
Network classes.
virtual void onException(std::exception &)
Final override from GNet::EventHandler.
Definition: gheapclient.cpp:76
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
void doDelete(const std::string &reason)
Calls onDelete() and then does a delayed "delete this".
Definition: gheapclient.cpp:63
A SimpleClient class for client objects that manage their own lifetime on the heap.
Definition: gheapclient.h:54
virtual void onDeleteImp(const std::string &reason, bool can_retry)
An alternative to onDelete() for private implementation classes.
Definition: gheapclient.cpp:82
void doDeleteForExit()
A destructor method that may be called at program termination when the normal doDelete() mechanism ha...
Definition: gheapclient.cpp:58
static bool synchronousDnsDefault()
Returns true if DNS queries should normally be synchronous on this platform.
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
A timer class template in which the timeout is delivered to the specified method. ...
Definition: gtimer.h:103
virtual void onConnecting()
Called just before the connection is initiated.
Definition: gheapclient.cpp:86