SEDNL  .
Simple Event Driven Network Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TCPClient.hpp
1 // SEDNL - Copyright (c) 2013 Jeremy S. Cochoy
2 //
3 // This software is provided 'as-is', without any express or implied warranty.
4 // In no event will the authors be held liable for any damages arising from
5 // the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 //
11 // 1. The origin of this software must not be misrepresented; you must not
12 // claim that you wrote the original software. If you use this software
13 // in a product, an acknowledgment in the product documentation would
14 // be appreciated but is not required.
15 //
16 // 2. Altered source versions must be plainly marked as such, and must not
17 // be misrepresented as being the original software.
18 //
19 // 3. This notice may not be removed or altered from any source
20 // distribution.
21 
22 #ifndef TCP_CLIENT_HPP_
23 #define TCP_CLIENT_HPP_
24 
25 #include "SEDNL/sednlfwd.hpp"
26 
27 #include "SEDNL/SocketHelp.hpp"
28 #include "SEDNL/Export.hpp"
29 #include "SEDNL/Connection.hpp"
30 
31 #include <vector>
32 
33 #ifdef SEDNL_WINDOWS
34 
35 #include <winsock2.h>
36 #include <Ws2tcpip.h>
37 #include <stdio.h>
38 
39 #else /* SEDNL_WINDOWS */
40 
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <netdb.h>
44 
45 #endif /* SEDNL_WINDOWS */
46 
47 namespace SedNL
48 {
49 
53 class SEDNL_API TCPClient : public Connection
54 {
55 public:
57  TCPClient() noexcept;
58 
67  TCPClient(const SocketAddress& socket_address, int timeout = 1000);
68 
91  void connect(const SocketAddress& socket_address, int timeout = 1000);
92 
93 private:
94 
101  bool blocking_connect(FileDescriptor fd, struct addrinfo *addr);
102 
110  bool non_blocking_connect(FileDescriptor fd, struct addrinfo *addr, int timeout);
111 };
112 
113 } // namespace SedNL
114 
115 #endif /* !TCPConnection */
116