Bond's TCP Library  1.0
Bond's TCP Client/Server Library
tcpclient.h
Go to the documentation of this file.
1 
10 #ifndef TCP_CLIENT_H
11 #define TCP_CLIENT_H
12 
13 #include <iostream>
14 #include <map>
15 #include <string.h>
16 #include <vector>
17 #include <deque>
18 #include <unistd.h>
19 #include <fcntl.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <sys/epoll.h>
23 #include <arpa/inet.h>
24 #include <netinet/ip.h>
25 #include <netdb.h>
26 #include "tcpsocket.h"
27 #include "tcpssl.h"
28 
29 namespace tcp {
30 
31 using namespace std;
32 using namespace tcp;
33 
35 class Client : public DataSocket {
36  public:
37 
42  Client(EPoll &epoll, SSLContext *ctx, const int domain = AF_INET, bool blocking = false) : DataSocket(epoll,domain,0,blocking), ctx_(ctx) {}
43 
48  virtual ~Client();
49 
54  SSLContext *ctx() { return ctx_; }
55 
57  SocketState state() { return state_; }
58 
60  in_port_t port() { return port_; }
61 
63  in_addr_t addr() { return addr_; }
64 
66  bool verifyPeer {false};
67 
69  string certfile;
70 
72  string keyfile;
73 
75  string keypass;
76 
81  bool checkPeerSubjectName { false };
82 
90  virtual bool connect(const char *host, const char *service);
91 
94 
95  protected:
96 
100  void handleEvents(uint32_t events) override;
101 
106  virtual void connected();
107 
108  friend class SSL;
109 
110  private:
111  in_port_t port_ {0};
112  in_addr_t addr_ {0};
113  SSLContext *ctx_;
114 };
115 
116 } // namespace mqtt
117 
118 #endif
tcp::Client::addr
in_addr_t addr()
Returns the ip address number used for the last call to connect()
Definition: tcpclient.h:63
tcp::Client::port
in_port_t port()
Returns the port number used for the last call to connect()
Definition: tcpclient.h:60
tcpsocket.h
Shared base classes for tcpclient.h and tcpserver.h.
tcp::SocketState
SocketState
Determines the state of a socket.
Definition: tcpsocket.h:58
tcp::DataSocket
Represents a buffered socket that can send and receive data using optional SSL encryption.
Definition: tcpsocket.h:159
tcp::SSL
Encapsulates an SSL connection data structure.
Definition: tcpssl.h:109
tcp::Client::Client
Client(EPoll &epoll, SSLContext *ctx, const int domain=AF_INET, bool blocking=false)
Creates a blocking or a non-blocking client.
Definition: tcpclient.h:42
tcp::Client
A blocking or non-blocking TCP client connection.
Definition: tcpclient.h:35
tcp::Client::keypass
string keypass
The password for the private key file, if required.
Definition: tcpclient.h:75
tcp::DataSocket::disconnect
void disconnect() override
Shuts down any SSL connection gracefully.
Definition: tcpsocket.cpp:189
tcp::SSLContext
Encapsulates an openSSL SSL_CTX record.
Definition: tcpssl.h:41
tcp::EPoll
Encapsulates the EPoll interface.
Definition: tcpsocket.h:72
tcp::Client::certfile
string certfile
The filename of the openSSL certificate in PEM format.
Definition: tcpclient.h:69
tcp::Client::state
SocketState state()
Return the client state.
Definition: tcpclient.h:57
tcpssl.h
Provides ssl client and server functionality.
tcp::Client::keyfile
string keyfile
The filename of the openSSL private key in PEM format.
Definition: tcpclient.h:72
tcp
A tcp client/server library for linux that supports openSSL and EPoll.
Definition: tcpclient.cpp:5
tcp::Client::ctx
SSLContext * ctx()
Returns the ssl context object.
Definition: tcpclient.h:54