The Battle for Wesnoth  1.13.11+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Static 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>

Inheritance diagram for wesnothd_connection:
Inheritance graph

Public Types

using error = wesnothd_connection_error
 

Public Member Functions

 wesnothd_connection (const wesnothd_connection &)=delete
 
wesnothd_connectionoperator= (const wesnothd_connection &)=delete
 
 ~wesnothd_connection ()
 
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
 

Static Public Member Functions

static wesnothd_connection_ptr create (const std::string &host, const std::string &service)
 

Private Types

typedef
boost::asio::ip::tcp::resolver 
resolver
 
typedef
boost::asio::ip::tcp::socket 
socket
 

Private Member Functions

 wesnothd_connection (const std::string &host, const std::string &service)
 Constructor. More...
 
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< boost::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 62 of file wesnothd_connection.hpp.

Member Typedef Documentation

Definition at line 65 of file wesnothd_connection.hpp.

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

Definition at line 147 of file wesnothd_connection.hpp.

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

Definition at line 150 of file wesnothd_connection.hpp.

Constructor & Destructor Documentation

wesnothd_connection::wesnothd_connection ( const wesnothd_connection )
delete

Referenced by create().

wesnothd_connection::~wesnothd_connection ( )

Definition at line 83 of file wesnothd_connection.cpp.

References MPTEST_LOG.

wesnothd_connection::wesnothd_connection ( const std::string &  host,
const std::string &  service 
)
private

Constructor.

May only be called via wesnothd_connection_ptr

Parameters
hostName of the host to connect to
serviceService identifier such as "80" or "http"

Definition at line 58 of file wesnothd_connection.cpp.

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

Member Function Documentation

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

Definition at line 127 of file wesnothd_connection.hpp.

References bytes_read_.

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

Definition at line 122 of file wesnothd_connection.hpp.

References bytes_to_read_.

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

Definition at line 112 of file wesnothd_connection.hpp.

References bytes_to_write_.

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

Definition at line 117 of file wesnothd_connection.hpp.

References bytes_written_.

void wesnothd_connection::cancel ( )

Definition at line 185 of file wesnothd_connection.cpp.

References MPTEST_LOG, socket_, and WRN_NW.

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

Definition at line 101 of file wesnothd_connection.cpp.

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

Referenced by handle_connect(), and handle_resolve().

wesnothd_connection_ptr wesnothd_connection::create ( const std::string &  host,
const std::string &  service 
)
static

Definition at line 441 of file wesnothd_connection.cpp.

References wesnothd_connection().

bool wesnothd_connection::fetch_data_with_loading_screen ( config cfg,
loading_stage  stage 
)
void wesnothd_connection::handle_connect ( const boost::system::error_code &  ec,
resolver::iterator  iterator 
)
private

Definition at line 109 of file wesnothd_connection.cpp.

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

Referenced by connect().

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

Definition at line 142 of file wesnothd_connection.cpp.

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

Referenced by handshake().

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

Definition at line 89 of file wesnothd_connection.cpp.

References connect(), LOG_NW, and MPTEST_LOG.

Referenced by wesnothd_connection().

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

Definition at line 237 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().

void wesnothd_connection::handshake ( )
private
bool wesnothd_connection::handshake_finished ( ) const
inline

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

Definition at line 107 of file wesnothd_connection.hpp.

References handshake_finished_.

bool wesnothd_connection::has_data_received ( ) const
inline

Definition at line 132 of file wesnothd_connection.hpp.

References recv_queue_.

Referenced by wait_and_receive_data().

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

Definition at line 137 of file wesnothd_connection.hpp.

References send_queue_.

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

Handles all pending asynchornous events and returns.

Definition at line 363 of file wesnothd_connection.cpp.

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

bool wesnothd_connection::receive_data ( config result)
void wesnothd_connection::recv ( )
private

Definition at line 353 of file wesnothd_connection.cpp.

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

Referenced by handle_handshake(), and handle_read().

void wesnothd_connection::send ( )
private
void wesnothd_connection::send_data ( const configr_of request)
void wesnothd_connection::stop ( )

Definition at line 209 of file wesnothd_connection.cpp.

References io_service_, and MPTEST_LOG.

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 404 of file wesnothd_connection.cpp.

References has_data_received(), and receive_data().

Referenced by fetch_data_with_loading_screen().

Member Data Documentation

std::size_t wesnothd_connection::bytes_read_
private

Definition at line 191 of file wesnothd_connection.hpp.

Referenced by bytes_read(), and is_read_complete().

std::size_t wesnothd_connection::bytes_to_read_
private

Definition at line 190 of file wesnothd_connection.hpp.

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

std::size_t wesnothd_connection::bytes_to_write_
private

Definition at line 188 of file wesnothd_connection.hpp.

Referenced by bytes_to_write(), is_write_complete(), and send().

std::size_t wesnothd_connection::bytes_written_
private

Definition at line 189 of file wesnothd_connection.hpp.

Referenced by bytes_written(), is_write_complete(), and send().

bool wesnothd_connection::handshake_finished_
private

Definition at line 157 of file wesnothd_connection.hpp.

Referenced by handle_handshake(), and handshake_finished().

data_union wesnothd_connection::handshake_response_
private

Definition at line 169 of file wesnothd_connection.hpp.

Referenced by handshake().

boost::asio::io_service wesnothd_connection::io_service_
private
boost::system::error_code wesnothd_connection::last_error_
private
std::mutex wesnothd_connection::last_error_mutex_
private
uint32_t wesnothd_connection::payload_size_
private

Definition at line 185 of file wesnothd_connection.hpp.

Referenced by send().

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

Definition at line 159 of file wesnothd_connection.hpp.

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

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

Definition at line 181 of file wesnothd_connection.hpp.

Referenced by handle_read(), has_data_received(), and receive_data().

std::mutex wesnothd_connection::recv_queue_mutex_
private

Definition at line 183 of file wesnothd_connection.hpp.

Referenced by handle_read(), and receive_data().

resolver wesnothd_connection::resolver_
private

Definition at line 148 of file wesnothd_connection.hpp.

Referenced by wesnothd_connection().

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

Definition at line 180 of file wesnothd_connection.hpp.

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

socket wesnothd_connection::socket_
private

Definition at line 151 of file wesnothd_connection.hpp.

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

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

Definition at line 143 of file wesnothd_connection.hpp.

Referenced by handle_handshake(), and poll().


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