A blocking or non-blocking TCP client connection. More...
#include <tcpclient.h>
Public Member Functions | |
Client (EPoll &epoll, SSLContext *ctx, const int domain=AF_INET, bool blocking=false) | |
Creates a blocking or a non-blocking client. More... | |
virtual | ~Client () |
Destroys the client. More... | |
SSLContext * | ctx () |
Returns the ssl context object. More... | |
SocketState | state () |
Return the client state. More... | |
in_port_t | port () |
Returns the port number used for the last call to connect() | |
in_addr_t | addr () |
Returns the ip address number used for the last call to connect() | |
virtual bool | connect (const char *host, const char *service) |
Initiates a connection to a server. More... | |
![]() | |
DataSocket (EPoll &epoll, const int domain=AF_INET, const int socket=0, const bool blocking=false, const int events=(EPOLLIN|EPOLLRDHUP)) | |
size_t | available () |
Returns the number of bytes available in the inputBuffer. | |
size_t | read (void *buffer, size_t size) |
Reads up to size bytes from inputBuffer into buffer. More... | |
size_t | write (const void *buffer, size_t size) |
Writes the contents of buffer to the outputBuffer. More... | |
![]() | |
Socket (EPoll &epoll, const int domain=AF_INET, const int socket=0, const bool blocking=false, const int events=(EPOLLIN|EPOLLRDHUP)) | |
Construct a blocking or non-blocking socket handle that responds to certain epoll events. More... | |
~Socket () | |
Closes and destroys the socket. More... | |
int | socket () const |
Return the linux socket handle. | |
int | domain () const |
Return the socket domain (AF_INET or AF_INET6) | |
Public Attributes | |
bool | verifyPeer {false} |
If true, openSSL will attempt to verify the peer certificate. | |
string | certfile |
The filename of the openSSL certificate in PEM format. | |
string | keyfile |
The filename of the openSSL private key in PEM format. | |
string | keypass |
The password for the private key file, if required. | |
bool | checkPeerSubjectName { false } |
Check if the peer certificate subject name matches the host name. More... | |
Protected Member Functions | |
void | handleEvents (uint32_t events) override |
Receive epoll events sent to this socket. More... | |
virtual void | connected () |
Called when the client connects to the server. More... | |
![]() | |
void | readToInputBuffer () |
Reads all available data from the socket into inputBuffer. | |
void | sendOutputBuffer () |
Writes all available data from the outputBuffer to the socket. More... | |
void | canSend (bool value) |
Sets the epoll event flags. More... | |
void | handleEvents (uint32_t events) override |
Called by the EPoll class when the listening socket recieves an epoll event. More... | |
void | disconnect () override |
Shuts down any SSL connection gracefully. More... | |
void | disconnected () override |
Called when a connection is disconnected. More... | |
virtual void | dataAvailable ()=0 |
Called whenever new data is appended to the inputBuffer. More... | |
virtual SSL * | createSSL (SSLContext *context) |
Factory method for returning an SSL object. More... | |
![]() | |
bool | setEvents (int events) |
Changes which epoll events the socket listens for. More... | |
EPoll & | epoll () |
Returns a reference to the epoll instance used by this socket. | |
Friends | |
class | SSL |
Additional Inherited Members | |
![]() | |
SSL * | ssl_ {nullptr} |
Exposes the underlying SSL record used for openSSL calls to descendant classes. | |
![]() | |
recursive_mutex | mtx |
The mutex used to provide exclusive access to the socket. | |
SocketState | state_ |
Descendant classes can manipulate the socket state directly. | |
A blocking or non-blocking TCP client connection.
Definition at line 35 of file tcpclient.h.
|
inline |
Creates a blocking or a non-blocking client.
doain | Either AF_INET or AF_INET6 |
blocking | If true, a blocking socket will be created. Otherwise a non-blocking socket is created |
Definition at line 42 of file tcpclient.h.
|
virtual |
Destroys the client.
Will call disconnect() first if necessary. This allows clients to be disconnected by destroying them.
Definition at line 9 of file tcpclient.cpp.
|
virtual |
Initiates a connection to a server.
If the client is a blocking client, the call blocks until a connection is established.
host | [in] The host or ip address of the server to connect to |
service | [in] The port number or service name to connect to |
Definition at line 16 of file tcpclient.cpp.
|
protectedvirtual |
Called when the client connects to the server.
Override connected() to perform operations when a connection is established The default implementation initiates the SSL_connect handshake.
Definition at line 87 of file tcpclient.cpp.
|
inline |
Returns the ssl context object.
A single SSLContext object is shared by all client connections in the library this allows default options, like a CA certificate, to be applied to all new client connections.
Definition at line 54 of file tcpclient.h.
|
overrideprotectedvirtual |
Receive epoll events sent to this socket.
Extends the behavior of DataSocket::handleEvents to monitors for an initial EPOLLIN signal when a new non-blocking connection has been established.
Implements tcp::Socket.
Definition at line 100 of file tcpclient.cpp.
|
inline |
Return the client state.
See the SocketState enum for possible values
Definition at line 57 of file tcpclient.h.
bool tcp::Client::checkPeerSubjectName { false } |
Check if the peer certificate subject name matches the host name.
If true and verifyPeer is true then this flag will cause an additional check that the server certificates subject name == the hostname used in the connect string. If it does not match the connection will not complete.
Definition at line 81 of file tcpclient.h.