A class that represents a TCP/IP connection. More...
#include <network_asio.hpp>
Public Member Functions | |
connection (const std::string &host, const std::string &service) | |
Constructor. More... | |
~connection () | |
void | transfer (const config &request, config &response) |
std::size_t | poll () |
Handle all pending asynchronous events and return. More... | |
void | run () |
Run asio's event loop. More... | |
void | cancel () |
bool | done () const |
True if connected and no high-level operation is in progress. More... | |
bool | using_tls () const |
True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens. More... | |
std::size_t | bytes_to_write () const |
std::size_t | bytes_written () const |
std::size_t | bytes_to_read () const |
std::size_t | bytes_read () const |
Private Types | |
typedef boost::asio::ip::tcp::resolver | resolver |
typedef std::unique_ptr< boost::asio::ip::tcp::socket > | raw_socket |
typedef std::unique_ptr< boost::asio::ssl::stream< raw_socket::element_type > > | tls_socket |
typedef utils::variant< raw_socket, tls_socket > | any_socket |
using | results_type = resolver::results_type |
using | endpoint = const boost::asio::ip::tcp::endpoint & |
Private Member Functions | |
void | handle_resolve (const boost::system::error_code &ec, results_type results) |
void | handle_connect (const boost::system::error_code &ec, endpoint endpoint) |
void | handshake () |
void | handle_handshake (const boost::system::error_code &ec) |
void | fallback_to_unencrypted () |
std::size_t | is_write_complete (const boost::system::error_code &error, std::size_t bytes_transferred) |
void | handle_write (const boost::system::error_code &ec, std::size_t bytes_transferred) |
std::size_t | is_read_complete (const boost::system::error_code &error, std::size_t bytes_transferred) |
void | handle_read (const boost::system::error_code &ec, std::size_t bytes_transferred, config &response) |
Private Attributes | |
boost::asio::io_context | io_context_ |
std::string | host_ |
const std::string | service_ |
resolver | resolver_ |
boost::asio::ssl::context | tls_context_ { boost::asio::ssl::context::sslv23 } |
bool | use_tls_ |
any_socket | socket_ |
bool | done_ |
std::unique_ptr< boost::asio::streambuf > | write_buf_ |
std::unique_ptr< boost::asio::streambuf > | read_buf_ |
uint32_t | handshake_response_ |
uint32_t | payload_size_ |
std::size_t | bytes_to_write_ |
std::size_t | bytes_written_ |
std::size_t | bytes_to_read_ |
std::size_t | bytes_read_ |
A class that represents a TCP/IP connection.
Definition at line 55 of file network_asio.hpp.
|
private |
Definition at line 141 of file network_asio.hpp.
|
private |
Definition at line 151 of file network_asio.hpp.
|
private |
Definition at line 139 of file network_asio.hpp.
|
private |
Definition at line 134 of file network_asio.hpp.
|
private |
Definition at line 150 of file network_asio.hpp.
|
private |
Definition at line 140 of file network_asio.hpp.
network_asio::connection::connection | ( | const std::string & | host, |
const std::string & | service | ||
) |
Constructor.
host | Name of the host to connect to |
service | Service identifier such as "80" or "http" |
Definition at line 64 of file network_asio.cpp.
References handle_resolve(), io_context_, LOG_NW, resolver_, and use_tls_.
network_asio::connection::~connection | ( | ) |
Definition at line 94 of file network_asio.cpp.
|
inline |
Definition at line 124 of file network_asio.hpp.
References bytes_read_.
Referenced by read_addon_connection_data::current(), and connect_connection_data::current().
|
inline |
Definition at line 119 of file network_asio.hpp.
References bytes_to_read_.
Referenced by read_addon_connection_data::total(), and connect_connection_data::total().
|
inline |
Definition at line 109 of file network_asio.hpp.
References bytes_to_write_.
Referenced by write_addon_connection_data::total().
|
inline |
Definition at line 114 of file network_asio.hpp.
References bytes_written_.
Referenced by write_addon_connection_data::current().
void network_asio::connection::cancel | ( | ) |
Definition at line 258 of file network_asio.cpp.
|
inline |
True if connected and no high-level operation is in progress.
Definition at line 96 of file network_asio.hpp.
References done_.
Referenced by read_addon_connection_data::finished(), connect_connection_data::finished(), and write_addon_connection_data::finished().
|
private |
Definition at line 218 of file network_asio.cpp.
References handle_connect(), socket_, and use_tls_.
Referenced by handle_handshake().
|
private |
Definition at line 116 of file network_asio.cpp.
References ERR_NW, handshake(), and LOG_NW.
Referenced by fallback_to_unencrypted(), and handle_resolve().
|
private |
Definition at line 164 of file network_asio.cpp.
References done_, fallback_to_unencrypted(), handshake_response_, host_, network_asio::load_tls_root_certs(), s, socket_, tls_context_, use_tls_, and network_asio::verbose_verify().
Referenced by handshake().
|
private |
Definition at line 334 of file network_asio.cpp.
References DBG_NW, and read_gz().
Referenced by transfer().
|
private |
Definition at line 106 of file network_asio.cpp.
References handle_connect(), and socket_.
Referenced by connection().
|
private |
Definition at line 296 of file network_asio.cpp.
References DBG_NW.
Referenced by handshake(), and transfer().
|
private |
Definition at line 128 of file network_asio.cpp.
References handle_handshake(), handle_write(), handshake_response_, socket_, and use_tls_.
Referenced by handle_connect().
|
private |
Definition at line 307 of file network_asio.cpp.
Referenced by transfer().
|
private |
Definition at line 286 of file network_asio.cpp.
Referenced by transfer().
|
inline |
Handle all pending asynchronous events and return.
Definition at line 70 of file network_asio.hpp.
References lg::err(), and io_context_.
Referenced by read_addon_connection_data::poll(), connect_connection_data::poll(), and write_addon_connection_data::poll().
|
inline |
Run asio's event loop.
Handle asynchronous events blocking until all asynchronous operations have finished.
Definition at line 88 of file network_asio.hpp.
References io_context_.
Definition at line 230 of file network_asio.cpp.
References bytes_to_write_, bytes_written_, done_, handle_read(), handle_write(), io_context_, is_read_complete(), is_write_complete(), payload_size_, read_buf_, socket_, write_buf_, and write_gz().
|
inline |
True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens.
Definition at line 102 of file network_asio.hpp.
|
private |
Definition at line 174 of file network_asio.hpp.
Referenced by bytes_read().
|
private |
Definition at line 173 of file network_asio.hpp.
Referenced by bytes_to_read().
|
private |
Definition at line 171 of file network_asio.hpp.
Referenced by bytes_to_write(), and transfer().
|
private |
Definition at line 172 of file network_asio.hpp.
Referenced by bytes_written(), and transfer().
|
private |
Definition at line 145 of file network_asio.hpp.
Referenced by done(), handle_handshake(), transfer(), and using_tls().
|
private |
Definition at line 159 of file network_asio.hpp.
Referenced by handle_handshake(), and handshake().
|
private |
Definition at line 132 of file network_asio.hpp.
Referenced by handle_handshake().
|
private |
Definition at line 130 of file network_asio.hpp.
Referenced by connection(), poll(), run(), and transfer().
|
private |
Definition at line 169 of file network_asio.hpp.
Referenced by transfer().
|
private |
Definition at line 148 of file network_asio.hpp.
Referenced by transfer().
|
private |
Definition at line 135 of file network_asio.hpp.
Referenced by connection().
|
private |
Definition at line 133 of file network_asio.hpp.
|
private |
Definition at line 143 of file network_asio.hpp.
Referenced by fallback_to_unencrypted(), handle_handshake(), handle_resolve(), handshake(), transfer(), using_tls(), and ~connection().
|
private |
Definition at line 137 of file network_asio.hpp.
Referenced by handle_handshake().
|
private |
Definition at line 142 of file network_asio.hpp.
Referenced by connection(), fallback_to_unencrypted(), handle_handshake(), and handshake().
|
private |
Definition at line 147 of file network_asio.hpp.
Referenced by transfer().