Async 1.8.0
AsyncTcpClientBase.h
Go to the documentation of this file.
1
30#ifndef ASYNC_TCP_CLIENT_BASE_INCLUDED
31#define ASYNC_TCP_CLIENT_BASE_INCLUDED
32
33
34/****************************************************************************
35 *
36 * System Includes
37 *
38 ****************************************************************************/
39
40#include <sigc++/sigc++.h>
41#include <stdint.h>
42
43#include <string>
44
45
46/****************************************************************************
47 *
48 * Project Includes
49 *
50 ****************************************************************************/
51
52#include <AsyncTcpConnection.h>
53#include <AsyncFdWatch.h>
54#include <AsyncDnsLookup.h>
55
56
57/****************************************************************************
58 *
59 * Local Includes
60 *
61 ****************************************************************************/
62
63
64
65/****************************************************************************
66 *
67 * Forward declarations
68 *
69 ****************************************************************************/
70
71
72
73/****************************************************************************
74 *
75 * Namespace
76 *
77 ****************************************************************************/
78
79namespace Async
80{
81
82/****************************************************************************
83 *
84 * Forward declarations of classes inside of the declared namespace
85 *
86 ****************************************************************************/
87
88class IpAddress;
89
90
91/****************************************************************************
92 *
93 * Defines & typedefs
94 *
95 ****************************************************************************/
96
97
98
99/****************************************************************************
100 *
101 * Exported Global Variables
102 *
103 ****************************************************************************/
104
105
106
107/****************************************************************************
108 *
109 * Class definitions
110 *
111 ****************************************************************************/
112
121class TcpClientBase : virtual public sigc::trackable
122{
123 public:
135
146 TcpClientBase(TcpConnection *con, const std::string& remote_host,
147 uint16_t remote_port);
148
159 TcpClientBase(TcpConnection *con, const IpAddress& remote_ip,
160 uint16_t remote_port);
161
165 virtual ~TcpClientBase(void);
166
173
182 std::string remoteHostName(void) const
183 {
184 if (!dns.label().empty())
185 {
186 return dns.label();
187 }
188 return con->remoteHost().toString();
189 }
190
195 void setBindIp(const IpAddress& bind_ip);
196
201 const IpAddress& bindIp(void) const { return bind_ip; }
202
213 void connect(const std::string &remote_host, uint16_t remote_port);
214
225 void connect(const Async::IpAddress& remote_ip, uint16_t remote_port);
226
235 void connect(void);
236
244 virtual void disconnect(void) = 0;
245
252 bool isIdle(void) const { return !dns.isPending() && (sock == -1); }
253
258 TcpConnection* conObj(void) { return con; }
259
263 sigc::signal<void> connected;
264
265 protected:
274 //virtual bool successfulConnect(void)
275 //{
276 // return m_successful_connect;
277 //}
278
285 virtual void closeConnection(void);
286
294 virtual void connectionEstablished(void)
295 {
296 //m_successful_connect = true;
298 }
299
300 virtual void emitConnected(void)
301 {
302 connected();
303 }
304
305 private:
306 TcpConnection * con;
307 DnsLookup dns;
308 int sock;
309 FdWatch wr_watch;
310 Async::IpAddress bind_ip;
311 //bool m_successful_connect = false;
312
313 void dnsResultsReady(DnsLookup& dns_lookup);
314 void connectToRemote(void);
315 void connectHandler(FdWatch *watch);
316
317}; /* class TcpClientBase */
318
319
320} /* namespace */
321
322#endif /* ASYNC_TCP_CLIENT_BASE_INCLUDED */
323
324
325
326/*
327 * This file has not been truncated
328 */
329
Contains a class for executing DNS queries.
Contains a watch for file descriptors.
Contains a class for handling exiting TCP connections.
A class for performing asynchronous DNS lookups.
const std::string & label(void) const
Return the associated label.
bool isPending(void) const
Check if a DNS lookup is pending.
A class for watching file descriptors.
A class for representing an IP address in an OS independent way.
std::string toString(void) const
Return the string representation of the IP address.
A base class for creating a TCP client connection.
TcpClientBase(TcpConnection *con, const IpAddress &remote_ip, uint16_t remote_port)
Constructor.
virtual void connectionEstablished(void)
Called when the connection has been established to the server.
virtual void closeConnection(void)
Check if the connection has been fully connected.
virtual ~TcpClientBase(void)
Destructor.
virtual void emitConnected(void)
TcpConnection * conObj(void)
Return the connection object for this client connection.
bool isIdle(void) const
Check if the connection is idle.
virtual TcpClientBase & operator=(TcpClientBase &&other)
Move assignmnt operator.
void connect(const Async::IpAddress &remote_ip, uint16_t remote_port)
Connect to the remote host.
sigc::signal< void > connected
A signal that is emitted when a connection has been established.
std::string remoteHostName(void) const
Get the name of the remote host as given to connect()
const IpAddress & bindIp(void) const
Get the bind IP address.
void connect(const std::string &remote_host, uint16_t remote_port)
Connect to the remote host.
TcpClientBase(TcpConnection *con, const std::string &remote_host, uint16_t remote_port)
Constructor.
TcpClientBase(TcpConnection *con)
Constructor.
void setBindIp(const IpAddress &bind_ip)
Bind to the interface having the specified IP address.
virtual void disconnect(void)=0
Disconnect from the remote host.
void connect(void)
Connect to the remote host.
A class for handling exiting TCP connections.
const IpAddress & remoteHost(void) const
Return the IP-address of the remote host.
Namespace for the asynchronous programming classes.