The Battle for Wesnoth  1.17.0-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 65 of file network_asio.cpp.

References bytes_read_, bytes_to_read_, bytes_to_write_, bytes_written_, done_, handle_resolve(), handshake_response_, io_context_, LOG_NW, payload_size_, read_buf_, resolver_, use_tls_, and write_buf_.

◆ ~connection()

network_asio::connection::~connection ( )

Definition at line 95 of file network_asio.cpp.

References socket_, and write().

Member Function Documentation

◆ bytes_read()

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

Definition at line 124 of file network_asio.hpp.

◆ bytes_to_read()

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

Definition at line 119 of file network_asio.hpp.

◆ bytes_to_write()

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

Definition at line 109 of file network_asio.hpp.

◆ bytes_written()

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

Definition at line 114 of file network_asio.hpp.

◆ cancel()

void network_asio::connection::cancel ( )

Definition at line 241 of file network_asio.cpp.

References bytes_read_, bytes_to_read_, bytes_to_write_, bytes_written_, socket_, and WRN_NW.

◆ 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.

◆ fallback_to_unencrypted()

void network_asio::connection::fallback_to_unencrypted ( )
private

Definition at line 201 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 117 of file network_asio.cpp.

References ERR_NW, handshake(), LOG_NW, and use_tls_.

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 317 of file network_asio.cpp.

References bytes_to_read_, bytes_to_write_, DBG_NW, done_, read_buf_, 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 107 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 279 of file network_asio.cpp.

References DBG_NW, and write_buf_.

Referenced by handshake(), and transfer().

◆ handshake()

void network_asio::connection::handshake ( )
private

Definition at line 132 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 290 of file network_asio.cpp.

References bytes_read_, bytes_to_read_, and read_buf_.

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 269 of file network_asio.cpp.

References bytes_to_write_, and bytes_written_.

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 game::error::error().

◆ 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.

◆ 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.

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 cancel(), connection(), and is_read_complete().

◆ bytes_to_read_

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

Definition at line 173 of file network_asio.hpp.

Referenced by cancel(), connection(), handle_read(), and is_read_complete().

◆ bytes_to_write_

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

Definition at line 171 of file network_asio.hpp.

Referenced by cancel(), connection(), handle_read(), is_write_complete(), and transfer().

◆ bytes_written_

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

Definition at line 172 of file network_asio.hpp.

Referenced by cancel(), connection(), is_write_complete(), and transfer().

◆ done_

bool network_asio::connection::done_
private

Definition at line 145 of file network_asio.hpp.

Referenced by connection(), handle_handshake(), handle_read(), and transfer().

◆ handshake_response_

uint32_t network_asio::connection::handshake_response_
private

Definition at line 159 of file network_asio.hpp.

Referenced by connection(), 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(), and transfer().

◆ payload_size_

uint32_t network_asio::connection::payload_size_
private

Definition at line 169 of file network_asio.hpp.

Referenced by connection(), and 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 connection(), handle_read(), is_read_complete(), and 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

◆ 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 connection(), handle_write(), and transfer().


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