Async  0.18.0
AsyncTcpClient.h
Go to the documentation of this file.
1 
36 #ifndef ASYNC_TCP_CLIENT_INCLUDED
37 #define ASYNC_TCP_CLIENT_INCLUDED
38 
39 
40 /****************************************************************************
41  *
42  * System Includes
43  *
44  ****************************************************************************/
45 
46 #include <sigc++/sigc++.h>
47 #include <stdint.h>
48 
49 #include <string>
50 
51 
52 /****************************************************************************
53  *
54  * Project Includes
55  *
56  ****************************************************************************/
57 
58 #include <AsyncTcpConnection.h>
59 
60 
61 /****************************************************************************
62  *
63  * Local Includes
64  *
65  ****************************************************************************/
66 
67 
68 
69 /****************************************************************************
70  *
71  * Forward declarations
72  *
73  ****************************************************************************/
74 
75 
76 
77 /****************************************************************************
78  *
79  * Namespace
80  *
81  ****************************************************************************/
82 
83 namespace Async
84 {
85 
86 /****************************************************************************
87  *
88  * Forward declarations of classes inside of the declared namespace
89  *
90  ****************************************************************************/
91 
92 class FdWatch;
93 class DnsLookup;
94 class IpAddress;
95 
96 
97 /****************************************************************************
98  *
99  * Defines & typedefs
100  *
101  ****************************************************************************/
102 
103 
104 
105 /****************************************************************************
106  *
107  * Exported Global Variables
108  *
109  ****************************************************************************/
110 
111 
112 
113 /****************************************************************************
114  *
115  * Class definitions
116  *
117  ****************************************************************************/
118 
130 class TcpClient : public TcpConnection
131 {
132  public:
143  TcpClient(const std::string& remote_host, uint16_t remote_port,
144  size_t recv_buf_len = DEFAULT_RECV_BUF_LEN);
145 
149  ~TcpClient(void);
150 
159  void connect(void);
160 
168  void disconnect(void);
169 
173  SigC::Signal0<void> connected;
174 
175 
176  protected:
177 
178  private:
179  DnsLookup *dns;
180  std::string remote_host;
181  uint16_t remote_port;
182  int sock;
183  FdWatch *wr_watch;
184 
185  void dnsResultsReady(DnsLookup& dns_lookup);
186  void connectToRemote(const IpAddress& ip_addr);
187  void connectHandler(FdWatch *watch);
188 
189 }; /* class TcpClient */
190 
191 
192 } /* namespace */
193 
194 #endif /* ASYNC_TCP_CLIENT_INCLUDED */
195 
196 
197 
198 /*
199  * This file has not been truncated
200  */
201 
A class for handling exiting TCP connections.
SigC::Signal0< void > connected
A signal that is emitted when a connection has been established.
static const int DEFAULT_RECV_BUF_LEN
The default length of the reception buffer.
A class for creating a TCP client connection.
void connect(void)
Connect to the remote host.
A class for watching file descriptors.
Definition: AsyncFdWatch.h:119
Contains a class for handling exiting TCP connections.
void disconnect(void)
Disconnect from the remote host.
~TcpClient(void)
Destructor.
A class for representing an IP address in an OS independent way.
A class for performing asynchronous DNS lookups.
TcpClient(const std::string &remote_host, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.