The Battle for Wesnoth  1.15.0-dev
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
wesnothd_connection Class Reference

A class that represents a TCP/IP connection to the wesnothd server. More...

#include <wesnothd_connection.hpp>

Public Types

using error = wesnothd_connection_error
 

Public Member Functions

 wesnothd_connection (const wesnothd_connection &)=delete
 
wesnothd_connectionoperator= (const wesnothd_connection &)=delete
 
 ~wesnothd_connection ()
 
 wesnothd_connection (const std::string &host, const std::string &service)
 Constructor. More...
 
bool fetch_data_with_loading_screen (config &cfg, loading_stage stage)
 
void send_data (const configr_of &request)
 
bool receive_data (config &result)
 
bool wait_and_receive_data (config &data)
 Helper function that spins until data has been received. More...
 
std::size_t poll ()
 Handles all pending asynchornous events and returns. More...
 
void cancel ()
 
void stop ()
 
bool handshake_finished () 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
 
bool has_data_received () const
 
bool is_sending_data () 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)
 
void send ()
 
void recv ()
 

Private Attributes

std::unique_ptr< std::thread > worker_thread_
 
boost::asio::io_service io_service_
 
resolver resolver_
 
socket socket_
 
boost::system::error_code last_error_
 
std::mutex last_error_mutex_
 
bool handshake_finished_
 
boost::asio::streambuf read_buf_
 
data_union handshake_response_
 
std::list< std::shared_ptr< boost::asio::streambuf > > send_queue_
 
std::list< configrecv_queue_
 
std::mutex recv_queue_mutex_
 
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 to the wesnothd server.

Definition at line 52 of file wesnothd_connection.hpp.

Member Typedef Documentation

◆ error

Definition at line 55 of file wesnothd_connection.hpp.

◆ resolver

typedef boost::asio::ip::tcp::resolver wesnothd_connection::resolver
private

Definition at line 132 of file wesnothd_connection.hpp.

◆ socket

typedef boost::asio::ip::tcp::socket wesnothd_connection::socket
private

Definition at line 135 of file wesnothd_connection.hpp.

Constructor & Destructor Documentation

◆ wesnothd_connection() [1/2]

wesnothd_connection::wesnothd_connection ( const wesnothd_connection )
delete

◆ ~wesnothd_connection()

wesnothd_connection::~wesnothd_connection ( )

Definition at line 82 of file wesnothd_connection.cpp.

References MPTEST_LOG, stop(), and worker_thread_.

◆ wesnothd_connection() [2/2]

wesnothd_connection::wesnothd_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 57 of file wesnothd_connection.cpp.

References handle_resolve(), LOG_NW, MPTEST_LOG, and resolver_.

Member Function Documentation

◆ bytes_read()

std::size_t wesnothd_connection::bytes_read ( ) const
inline

Definition at line 112 of file wesnothd_connection.hpp.

◆ bytes_to_read()

std::size_t wesnothd_connection::bytes_to_read ( ) const
inline

Definition at line 107 of file wesnothd_connection.hpp.

◆ bytes_to_write()

std::size_t wesnothd_connection::bytes_to_write ( ) const
inline

Definition at line 97 of file wesnothd_connection.hpp.

◆ bytes_written()

std::size_t wesnothd_connection::bytes_written ( ) const
inline

Definition at line 102 of file wesnothd_connection.hpp.

◆ cancel()

void wesnothd_connection::cancel ( )

Definition at line 187 of file wesnothd_connection.cpp.

References MPTEST_LOG, socket_, and WRN_NW.

◆ connect()

void wesnothd_connection::connect ( resolver::iterator  iterator)
private

Definition at line 106 of file wesnothd_connection.cpp.

References handle_connect(), LOG_NW, MPTEST_LOG, and socket_.

Referenced by handle_connect(), and handle_resolve().

◆ fetch_data_with_loading_screen()

bool wesnothd_connection::fetch_data_with_loading_screen ( config cfg,
loading_stage  stage 
)

◆ handle_connect()

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

Definition at line 114 of file wesnothd_connection.cpp.

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

Referenced by connect().

◆ handle_handshake()

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

Definition at line 147 of file wesnothd_connection.cpp.

References handshake_finished_, io_service_, LOG_NW, MPTEST_LOG, recv(), and worker_thread_.

Referenced by handshake().

◆ handle_read()

void wesnothd_connection::handle_read ( const boost::system::error_code &  ec,
std::size_t  bytes_transferred 
)
private

◆ handle_resolve()

void wesnothd_connection::handle_resolve ( const boost::system::error_code &  ec,
resolver::iterator  iterator 
)
private

Definition at line 94 of file wesnothd_connection.cpp.

References connect(), LOG_NW, and MPTEST_LOG.

Referenced by wesnothd_connection().

◆ handle_write()

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

Definition at line 239 of file wesnothd_connection.cpp.

References DBG_NW, io_service_, last_error_, last_error_mutex_, LOG_NW, MPTEST_LOG, send(), and send_queue_.

Referenced by send().

◆ handshake()

void wesnothd_connection::handshake ( )
private

◆ handshake_finished()

bool wesnothd_connection::handshake_finished ( ) const
inline

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

Definition at line 92 of file wesnothd_connection.hpp.

◆ has_data_received()

bool wesnothd_connection::has_data_received ( ) const
inline

Definition at line 117 of file wesnothd_connection.hpp.

Referenced by wait_and_receive_data().

◆ is_read_complete()

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

◆ is_sending_data()

bool wesnothd_connection::is_sending_data ( ) const
inline

Definition at line 122 of file wesnothd_connection.hpp.

◆ is_write_complete()

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

◆ operator=()

wesnothd_connection& wesnothd_connection::operator= ( const wesnothd_connection )
delete

◆ poll()

std::size_t wesnothd_connection::poll ( )

Handles all pending asynchornous events and returns.

Definition at line 366 of file wesnothd_connection.cpp.

References lg::err(), io_service_, MPTEST_LOG, worker_thread_, and WRN_NW.

Referenced by BOOST_AUTO_TEST_CASE().

◆ receive_data()

bool wesnothd_connection::receive_data ( config result)

◆ recv()

void wesnothd_connection::recv ( )
private

Definition at line 356 of file wesnothd_connection.cpp.

References handle_read(), is_read_complete(), MPTEST_LOG, read_buf_, and socket_.

Referenced by handle_handshake(), and handle_read().

◆ send()

void wesnothd_connection::send ( )
private

◆ send_data()

void wesnothd_connection::send_data ( const configr_of request)

◆ stop()

void wesnothd_connection::stop ( )

Definition at line 211 of file wesnothd_connection.cpp.

References io_service_, and MPTEST_LOG.

Referenced by ~wesnothd_connection().

◆ wait_and_receive_data()

bool wesnothd_connection::wait_and_receive_data ( config data)

Helper function that spins until data has been received.

Should be used in tandem with the loading screen or other multi-threaded components.

Definition at line 413 of file wesnothd_connection.cpp.

References has_data_received(), last_error_, last_error_mutex_, and receive_data().

Referenced by fetch_data_with_loading_screen().

Member Data Documentation

◆ bytes_read_

std::size_t wesnothd_connection::bytes_read_
private

Definition at line 176 of file wesnothd_connection.hpp.

Referenced by is_read_complete().

◆ bytes_to_read_

std::size_t wesnothd_connection::bytes_to_read_
private

Definition at line 175 of file wesnothd_connection.hpp.

Referenced by handle_read(), and is_read_complete().

◆ bytes_to_write_

std::size_t wesnothd_connection::bytes_to_write_
private

Definition at line 173 of file wesnothd_connection.hpp.

Referenced by is_write_complete(), and send().

◆ bytes_written_

std::size_t wesnothd_connection::bytes_written_
private

Definition at line 174 of file wesnothd_connection.hpp.

Referenced by is_write_complete(), and send().

◆ handshake_finished_

bool wesnothd_connection::handshake_finished_
private

Definition at line 142 of file wesnothd_connection.hpp.

Referenced by handle_handshake().

◆ handshake_response_

data_union wesnothd_connection::handshake_response_
private

Definition at line 154 of file wesnothd_connection.hpp.

Referenced by handshake().

◆ io_service_

boost::asio::io_service wesnothd_connection::io_service_
private

◆ last_error_

boost::system::error_code wesnothd_connection::last_error_
private

◆ last_error_mutex_

std::mutex wesnothd_connection::last_error_mutex_
private

◆ payload_size_

uint32_t wesnothd_connection::payload_size_
private

Definition at line 170 of file wesnothd_connection.hpp.

Referenced by send().

◆ read_buf_

boost::asio::streambuf wesnothd_connection::read_buf_
private

Definition at line 144 of file wesnothd_connection.hpp.

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

◆ recv_queue_

std::list<config> wesnothd_connection::recv_queue_
private

Definition at line 166 of file wesnothd_connection.hpp.

Referenced by handle_read(), and receive_data().

◆ recv_queue_mutex_

std::mutex wesnothd_connection::recv_queue_mutex_
private

Definition at line 168 of file wesnothd_connection.hpp.

Referenced by handle_read(), and receive_data().

◆ resolver_

resolver wesnothd_connection::resolver_
private

Definition at line 133 of file wesnothd_connection.hpp.

Referenced by wesnothd_connection().

◆ send_queue_

std::list<std::shared_ptr<boost::asio::streambuf> > wesnothd_connection::send_queue_
private

Definition at line 165 of file wesnothd_connection.hpp.

Referenced by handle_write(), send(), and send_data().

◆ socket_

socket wesnothd_connection::socket_
private

Definition at line 136 of file wesnothd_connection.hpp.

Referenced by cancel(), connect(), handle_connect(), handshake(), recv(), and send().

◆ worker_thread_

std::unique_ptr<std::thread> wesnothd_connection::worker_thread_
private

Definition at line 128 of file wesnothd_connection.hpp.

Referenced by handle_handshake(), poll(), and ~wesnothd_connection().


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