Async  1.4.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  explicit TcpClient(size_t recv_buf_len = DEFAULT_RECV_BUF_LEN);
144 
155  TcpClient(const std::string& remote_host, uint16_t remote_port,
156  size_t recv_buf_len = DEFAULT_RECV_BUF_LEN);
157 
168  TcpClient(const IpAddress& remote_ip, uint16_t remote_port,
169  size_t recv_buf_len = DEFAULT_RECV_BUF_LEN);
170 
174  ~TcpClient(void);
175 
180  void bind(const IpAddress& bind_ip);
181 
192  void connect(const std::string &remote_host, uint16_t remote_port);
193 
204  void connect(const Async::IpAddress& remote_ip, uint16_t remote_port);
205 
214  void connect(void);
215 
223  void disconnect(void);
224 
231  bool isIdle(void) const { return TcpConnection::isIdle() && (sock == -1); }
232 
236  sigc::signal<void> connected;
237 
238 
239  protected:
240 
241  private:
242  DnsLookup * dns;
243  std::string remote_host;
244  int sock;
245  FdWatch * wr_watch;
246  Async::IpAddress bind_ip;
247 
248  void dnsResultsReady(DnsLookup& dns_lookup);
249  void connectToRemote(void);
250  void connectHandler(FdWatch *watch);
251 
252 }; /* class TcpClient */
253 
254 
255 } /* namespace */
256 
257 #endif /* ASYNC_TCP_CLIENT_INCLUDED */
258 
259 
260 
261 /*
262  * This file has not been truncated
263  */
264 
A class for handling exiting TCP connections.
TcpClient(size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
Constructor.
static const int DEFAULT_RECV_BUF_LEN
The default length of the reception buffer.
bool isIdle(void) const
Check if the connection is idle.
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.
Namespace for the asynchronous programming classes.
void disconnect(void)
Disconnect from the remote host.
~TcpClient(void)
Destructor.
sigc::signal< void > connected
A signal that is emitted when a connection has been established.
A class for representing an IP address in an OS independent way.
void bind(const IpAddress &bind_ip)
Bind to the interface having the specified IP address.
A class for performing asynchronous DNS lookups.
bool isIdle(void) const
Check if the connection is idle.