The Battle for Wesnoth  1.19.5+dev
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
network_asio::connection Class Reference

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_socketany_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_
 

Detailed Description

A class that represents a TCP/IP connection.

Definition at line 55 of file network_asio.hpp.

Member Typedef Documentation

◆ any_socket

Definition at line 141 of file network_asio.hpp.

◆ endpoint

using network_asio::connection::endpoint = const boost::asio::ip::tcp::endpoint&
private

Definition at line 151 of file network_asio.hpp.

◆ raw_socket

typedef std::unique_ptr<boost::asio::ip::tcp::socket> network_asio::connection::raw_socket
private

Definition at line 139 of file network_asio.hpp.

◆ resolver

typedef boost::asio::ip::tcp::resolver network_asio::connection::resolver
private

Definition at line 134 of file network_asio.hpp.

◆ results_type

using network_asio::connection::results_type = resolver::results_type
private

Definition at line 150 of file network_asio.hpp.

◆ tls_socket

typedef std::unique_ptr<boost::asio::ssl::stream<raw_socket::element_type> > network_asio::connection::tls_socket
private

Definition at line 140 of file network_asio.hpp.

Constructor & Destructor Documentation

◆ connection()

network_asio::connection::connection ( const std::string &  host,
const std::string &  service 
)

Constructor.

Parameters
hostName of the host to connect to
serviceService 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_.

◆ ~connection()

network_asio::connection::~connection ( )

Definition at line 94 of file network_asio.cpp.

References socket_, and write().

Member Function Documentation

◆ bytes_read()

std::size_t network_asio::connection::bytes_read ( ) const
inline

◆ bytes_to_read()

std::size_t network_asio::connection::bytes_to_read ( ) const
inline

◆ bytes_to_write()

std::size_t network_asio::connection::bytes_to_write ( ) const
inline

Definition at line 109 of file network_asio.hpp.

References bytes_to_write_.

Referenced by write_addon_connection_data::total().

◆ bytes_written()

std::size_t network_asio::connection::bytes_written ( ) const
inline

Definition at line 114 of file network_asio.hpp.

References bytes_written_.

Referenced by write_addon_connection_data::current().

◆ cancel()

void network_asio::connection::cancel ( )

Definition at line 258 of file network_asio.cpp.

◆ done()

bool network_asio::connection::done ( ) const
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().

◆ fallback_to_unencrypted()

void network_asio::connection::fallback_to_unencrypted ( )
private

Definition at line 218 of file network_asio.cpp.

References handle_connect(), socket_, and use_tls_.

Referenced by handle_handshake().

◆ handle_connect()

void network_asio::connection::handle_connect ( const boost::system::error_code &  ec,
endpoint  endpoint 
)
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().

◆ handle_handshake()

void network_asio::connection::handle_handshake ( const boost::system::error_code &  ec)
private

◆ handle_read()

void network_asio::connection::handle_read ( const boost::system::error_code &  ec,
std::size_t  bytes_transferred,
config response 
)
private

Definition at line 334 of file network_asio.cpp.

References DBG_NW, and read_gz().

Referenced by transfer().

◆ handle_resolve()

void network_asio::connection::handle_resolve ( const boost::system::error_code &  ec,
results_type  results 
)
private

Definition at line 106 of file network_asio.cpp.

References handle_connect(), and socket_.

Referenced by connection().

◆ handle_write()

void network_asio::connection::handle_write ( const boost::system::error_code &  ec,
std::size_t  bytes_transferred 
)
private

Definition at line 296 of file network_asio.cpp.

References DBG_NW.

Referenced by handshake(), and transfer().

◆ handshake()

void network_asio::connection::handshake ( )
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().

◆ is_read_complete()

std::size_t network_asio::connection::is_read_complete ( const boost::system::error_code &  error,
std::size_t  bytes_transferred 
)
private

Definition at line 307 of file network_asio.cpp.

Referenced by transfer().

◆ is_write_complete()

std::size_t network_asio::connection::is_write_complete ( const boost::system::error_code &  error,
std::size_t  bytes_transferred 
)
private

Definition at line 286 of file network_asio.cpp.

Referenced by transfer().

◆ poll()

std::size_t network_asio::connection::poll ( )
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().

◆ run()

void network_asio::connection::run ( )
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_.

◆ transfer()

void network_asio::connection::transfer ( const config request,
config response 
)

◆ using_tls()

bool network_asio::connection::using_tls ( ) const
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.

References done_, and socket_.

Member Data Documentation

◆ bytes_read_

std::size_t network_asio::connection::bytes_read_
private

Definition at line 174 of file network_asio.hpp.

Referenced by bytes_read().

◆ bytes_to_read_

std::size_t network_asio::connection::bytes_to_read_
private

Definition at line 173 of file network_asio.hpp.

Referenced by bytes_to_read().

◆ bytes_to_write_

std::size_t network_asio::connection::bytes_to_write_
private

Definition at line 171 of file network_asio.hpp.

Referenced by bytes_to_write(), and transfer().

◆ bytes_written_

std::size_t network_asio::connection::bytes_written_
private

Definition at line 172 of file network_asio.hpp.

Referenced by bytes_written(), and transfer().

◆ done_

bool network_asio::connection::done_
private

Definition at line 145 of file network_asio.hpp.

Referenced by done(), handle_handshake(), transfer(), and using_tls().

◆ handshake_response_

uint32_t network_asio::connection::handshake_response_
private

Definition at line 159 of file network_asio.hpp.

Referenced by handle_handshake(), and handshake().

◆ host_

std::string network_asio::connection::host_
private

Definition at line 132 of file network_asio.hpp.

Referenced by handle_handshake().

◆ io_context_

boost::asio::io_context network_asio::connection::io_context_
private

Definition at line 130 of file network_asio.hpp.

Referenced by connection(), poll(), run(), and transfer().

◆ payload_size_

uint32_t network_asio::connection::payload_size_
private

Definition at line 169 of file network_asio.hpp.

Referenced by transfer().

◆ read_buf_

std::unique_ptr<boost::asio::streambuf> network_asio::connection::read_buf_
private

Definition at line 148 of file network_asio.hpp.

Referenced by transfer().

◆ resolver_

resolver network_asio::connection::resolver_
private

Definition at line 135 of file network_asio.hpp.

Referenced by connection().

◆ service_

const std::string network_asio::connection::service_
private

Definition at line 133 of file network_asio.hpp.

◆ socket_

any_socket network_asio::connection::socket_
private

◆ tls_context_

boost::asio::ssl::context network_asio::connection::tls_context_ { boost::asio::ssl::context::sslv23 }
private

Definition at line 137 of file network_asio.hpp.

Referenced by handle_handshake().

◆ use_tls_

bool network_asio::connection::use_tls_
private

Definition at line 142 of file network_asio.hpp.

Referenced by connection(), fallback_to_unencrypted(), handle_handshake(), and handshake().

◆ write_buf_

std::unique_ptr<boost::asio::streambuf> network_asio::connection::write_buf_
private

Definition at line 147 of file network_asio.hpp.

Referenced by transfer().


The documentation for this class was generated from the following files: