The Battle for Wesnoth  1.15.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...
 
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
 

Private Member Functions

void handle_resolve (const boost::system::error_code &ec, resolver::iterator iterator)
 
void connect (resolver::iterator iterator)
 
void handle_connect (const boost::system::error_code &ec, resolver::iterator iterator)
 
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_service_
 
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 55 of file network_asio.hpp.

Member Typedef Documentation

◆ resolver

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

Definition at line 123 of file network_asio.hpp.

◆ socket

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

Definition at line 126 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 58 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 115 of file network_asio.hpp.

◆ bytes_to_read()

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

Definition at line 110 of file network_asio.hpp.

◆ bytes_to_write()

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

Definition at line 100 of file network_asio.hpp.

◆ bytes_written()

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

Definition at line 105 of file network_asio.hpp.

◆ cancel()

void network_asio::connection::cancel ( )

Definition at line 157 of file network_asio.cpp.

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

◆ connect()

void network_asio::connection::connect ( resolver::iterator  iterator)
private

Definition at line 87 of file network_asio.cpp.

References handle_connect(), LOG_NW, and socket_.

Referenced by handle_connect(), and handle_resolve().

◆ done()

bool network_asio::connection::done ( ) const
inline

True if connected and no high-level operation is in progress.

Definition at line 95 of file network_asio.hpp.

◆ handle_connect()

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

Definition at line 93 of file network_asio.cpp.

References connect(), ERR_NW, handshake(), LOG_NW, socket_, and WRN_NW.

Referenced by connect().

◆ handle_handshake()

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

Definition at line 122 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 231 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,
resolver::iterator  iterator 
)
private

Definition at line 78 of file network_asio.cpp.

References connect().

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 193 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 204 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 183 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 69 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 87 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 155 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 154 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 152 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 153 of file network_asio.hpp.

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

◆ done_

bool network_asio::connection::done_
private

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

Referenced by handshake().

◆ io_service_

boost::asio::io_service network_asio::connection::io_service_
private

Definition at line 121 of file network_asio.hpp.

Referenced by transfer().

◆ payload_size_

uint32_t network_asio::connection::payload_size_
private

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

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

◆ resolver_

resolver network_asio::connection::resolver_
private

Definition at line 124 of file network_asio.hpp.

Referenced by connection().

◆ socket_

socket network_asio::connection::socket_
private

Definition at line 127 of file network_asio.hpp.

Referenced by cancel(), connect(), handle_connect(), handshake(), and transfer().

◆ write_buf_

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

Definition at line 131 of file network_asio.hpp.

Referenced by handle_write(), and transfer().


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