diff options
author | Jonas Smedegaard <dr@jones.dk> | 2017-06-24 09:21:37 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2017-06-24 09:21:37 +0200 |
commit | 3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb (patch) | |
tree | 9a5684babcd16d302fbe59c56b6045660ad62488 /src/network/tcp_client_socket_handler.hpp | |
parent | f9cee98aacd6aea8ccb7f5677b4ff1e1e234e4d1 (diff) | |
parent | c21cbbf9667991d2b928562a9c199e625d3f9bba (diff) | |
download | biboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.tar.gz biboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.tar.bz2 biboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.tar.xz biboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.zip |
Updated version 5.0 from 'upstream/5.0'
with Debian dir 2ae31d03ffb1d79153a692af23c7b2b097cc4b2b
Diffstat (limited to 'src/network/tcp_client_socket_handler.hpp')
-rw-r--r-- | src/network/tcp_client_socket_handler.hpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/network/tcp_client_socket_handler.hpp b/src/network/tcp_client_socket_handler.hpp new file mode 100644 index 0000000..74caca9 --- /dev/null +++ b/src/network/tcp_client_socket_handler.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include <network/tcp_socket_handler.hpp> + +class TCPClientSocketHandler: public TCPSocketHandler +{ + public: + TCPClientSocketHandler(std::shared_ptr<Poller>& poller); + ~TCPClientSocketHandler(); + /** + * Connect to the remote server, and call on_connected() if this + * succeeds. If tls is true, we set use_tls to true and will also call + * start_tls() when the connection succeeds. + */ + void connect(const std::string& address, const std::string& port, const bool tls); + void connect() override final; + /** + * Called by a TimedEvent, when the connection did not succeed or fail + * after a given time. + */ + void on_connection_timeout(); + /** + * Called when the connection is successful. + */ + virtual void on_connected() = 0; + bool is_connected() const override; + bool is_connecting() const override; + + std::string get_port() const; + + void close() override final; + std::chrono::system_clock::time_point connection_date; + + /** + * Whether or not this connection is using the two given TCP ports. + */ + bool match_port_pairt(const uint16_t local, const uint16_t remote) const; + + protected: + bool hostname_resolution_failed; + /** + * Address to bind the socket to, before calling connect(). + * If empty, it’s equivalent to binding to INADDR_ANY. + */ + std::string bind_addr; + /** + * Display the resolved IP, just for information purpose. + */ + void display_resolved_ip(struct addrinfo* rp) const; + private: + /** + * Initialize the socket with the parameters contained in the given + * addrinfo structure. + */ + void init_socket(const struct addrinfo* rp); + /** + * DNS resolver + */ + Resolver resolver; + /** + * Keep the details of the addrinfo returned by the resolver that + * triggered a EINPROGRESS error when connect()ing to it, to reuse it + * directly when connect() is called again. + */ + struct addrinfo addrinfo{}; + struct sockaddr_in6 ai_addr{}; + socklen_t ai_addrlen{}; + + /** + * Hostname we are connected/connecting to + */ + std::string address; + /** + * Port we are connected/connecting to + */ + std::string port; + + uint16_t local_port{}; + + bool connected; + bool connecting; +}; |