The Battle for Wesnoth  1.15.12+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...
 
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...
 
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 boost::asio::ip::tcp::socket socket
 
using results_type = resolver::iterator
 
using endpoint = resolver::iterator
 

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)
 
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_service io_context_
 
resolver resolver_
 
socket socket_
 
bool done_
 
std::unique_ptr< boost::asio::streambuf > write_buf_
 
std::unique_ptr< boost::asio::streambuf > read_buf_
 
data_union 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 61 of file network_asio.hpp.

Member Typedef Documentation

◆ endpoint

using network_asio::connection::endpoint = resolver::iterator
private

Definition at line 149 of file network_asio.hpp.

◆ resolver

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

Definition at line 133 of file network_asio.hpp.

◆ results_type

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

Definition at line 148 of file network_asio.hpp.

◆ socket

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

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

References handle_resolve(), LOG_NW, and resolver_.

Member Function Documentation

◆ bytes_read()

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

Definition at line 121 of file network_asio.hpp.

◆ bytes_to_read()

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

Definition at line 116 of file network_asio.hpp.

◆ bytes_to_write()

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

Definition at line 106 of file network_asio.hpp.

◆ bytes_written()

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

Definition at line 111 of file network_asio.hpp.

◆ cancel()

void network_asio::connection::cancel ( )

Definition at line 166 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 101 of file network_asio.hpp.

◆ handle_connect()

void network_asio::connection::handle_connect ( const boost::system::error_code &  ec,
endpoint  endpoint 
)
private

Definition at line 101 of file network_asio.cpp.

References ERR_NW, handshake(), and LOG_NW.

Referenced by handle_resolve().

◆ handle_handshake()

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

Definition at line 127 of file network_asio.cpp.

References done_.

Referenced by handshake().

◆ 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 240 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 91 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 202 of file network_asio.cpp.

References DBG_NW, and write_buf_.

Referenced by handshake(), and transfer().

◆ handshake()

void network_asio::connection::handshake ( )
private

◆ 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 213 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 192 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 75 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 93 of file network_asio.hpp.

◆ transfer()

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

Member Data Documentation

◆ bytes_read_

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

Definition at line 171 of file network_asio.hpp.

Referenced by cancel(), and is_read_complete().

◆ bytes_to_read_

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

Definition at line 170 of file network_asio.hpp.

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

◆ bytes_to_write_

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

Definition at line 168 of file network_asio.hpp.

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

◆ bytes_written_

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

Definition at line 169 of file network_asio.hpp.

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

◆ done_

bool network_asio::connection::done_
private

Definition at line 139 of file network_asio.hpp.

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

◆ handshake_response_

data_union network_asio::connection::handshake_response_
private

Definition at line 158 of file network_asio.hpp.

Referenced by handshake().

◆ io_context_

boost::asio::io_service network_asio::connection::io_context_
private

Definition at line 130 of file network_asio.hpp.

Referenced by transfer().

◆ payload_size_

uint32_t network_asio::connection::payload_size_
private

Definition at line 166 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 142 of file network_asio.hpp.

Referenced by handle_read(), is_read_complete(), and transfer().

◆ resolver_

resolver network_asio::connection::resolver_
private

Definition at line 134 of file network_asio.hpp.

Referenced by connection().

◆ socket_

socket network_asio::connection::socket_
private

Definition at line 137 of file network_asio.hpp.

Referenced by cancel(), handle_resolve(), handshake(), and transfer().

◆ write_buf_

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

Definition at line 141 of file network_asio.hpp.

Referenced by handle_write(), and transfer().


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