The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
twesnothd_connection Class Reference

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

#include <wesnothd_connection.hpp>

Inheritance diagram for twesnothd_connection:
Inheritance graph

Public Types

using error = wesnothd_connection_error
 

Public Member Functions

 twesnothd_connection (const std::string &host, const std::string &service)
 Constructor. More...
 
void send_data (const configr_of &request)
 
bool receive_data (config &result)
 
std::size_t poll ()
 Handle all pending asynchonous events and return. More...
 
void cancel ()
 Run asio's event loop. More...
 
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

boost::asio::io_service io_service_
 
resolver resolver_
 
socket socket_
 
bool handshake_finished_
 
boost::asio::streambuf read_buf_
 
union {
   char   binary [4]
 
   boost::uint32_t   num
 
handshake_response_
 
std::list< boost::asio::streambuf > send_queue_
 
std::list< configrecv_queue_
 
boost::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 40 of file wesnothd_connection.hpp.

Member Typedef Documentation

Definition at line 43 of file wesnothd_connection.hpp.

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

Definition at line 96 of file wesnothd_connection.hpp.

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

Definition at line 99 of file wesnothd_connection.hpp.

Constructor & Destructor Documentation

twesnothd_connection::twesnothd_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 33 of file wesnothd_connection.cpp.

References handle_resolve(), LOG_NW, and resolver_.

Member Function Documentation

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

Definition at line 82 of file wesnothd_connection.hpp.

References bytes_read_.

Referenced by dialogs::read_wesnothd_connection_data::current().

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

Definition at line 78 of file wesnothd_connection.hpp.

References bytes_to_read_.

Referenced by dialogs::read_wesnothd_connection_data::total().

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

Definition at line 70 of file wesnothd_connection.hpp.

References bytes_to_write_.

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

Definition at line 74 of file wesnothd_connection.hpp.

References bytes_written_.

void twesnothd_connection::cancel ( )

Run asio's event loop.

Handle asynchronous events blocking until all asynchronous operations have finished

Definition at line 126 of file wesnothd_connection.cpp.

References socket_, and WRN_NW.

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

Definition at line 61 of file wesnothd_connection.cpp.

References handle_connect(), LOG_NW, and socket_.

Referenced by handle_connect(), and handle_resolve().

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

Definition at line 69 of file wesnothd_connection.cpp.

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

Referenced by connect().

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

Definition at line 105 of file wesnothd_connection.cpp.

References handshake_finished_, and recv().

Referenced by handshake().

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

Definition at line 185 of file wesnothd_connection.cpp.

References bytes_to_read_, DBG_NW, read_buf_, read_gz(), recv(), and recv_queue_.

Referenced by recv().

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

Definition at line 53 of file wesnothd_connection.cpp.

References connect().

Referenced by twesnothd_connection().

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

Definition at line 145 of file wesnothd_connection.cpp.

References DBG_NW, send(), and send_queue_.

Referenced by send().

void twesnothd_connection::handshake ( )
private

Definition at line 92 of file wesnothd_connection.cpp.

References handle_handshake(), handshake_response_, and socket_.

Referenced by handle_connect().

bool twesnothd_connection::handshake_finished ( ) const
inline

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

Definition at line 68 of file wesnothd_connection.hpp.

References handshake_finished_.

Referenced by dialogs::connect_wesnothd_connection_data::finished().

bool twesnothd_connection::has_data_received ( ) const
inline

Definition at line 86 of file wesnothd_connection.hpp.

References recv_queue_.

Referenced by dialogs::read_wesnothd_connection_data::finished().

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

Definition at line 160 of file wesnothd_connection.cpp.

References bytes_read_, bytes_to_read_, num, and read_buf_.

Referenced by recv().

bool twesnothd_connection::is_sending_data ( ) const
inline

Definition at line 90 of file wesnothd_connection.hpp.

References send_queue_.

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

Definition at line 137 of file wesnothd_connection.cpp.

References bytes_to_write_, and bytes_written_.

Referenced by send().

std::size_t twesnothd_connection::poll ( )

Handle all pending asynchonous events and return.

Definition at line 227 of file wesnothd_connection.cpp.

References lg::err(), and io_service_.

Referenced by dialogs::read_wesnothd_connection_data::poll(), dialogs::connect_wesnothd_connection_data::poll(), receive_data(), and send_data().

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

Definition at line 219 of file wesnothd_connection.cpp.

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

Referenced by handle_handshake(), and handle_read().

void twesnothd_connection::send ( )
private
void twesnothd_connection::send_data ( const configr_of request)

Member Data Documentation

char twesnothd_connection::binary[4]

Definition at line 121 of file wesnothd_connection.hpp.

std::size_t twesnothd_connection::bytes_read_
private

Definition at line 140 of file wesnothd_connection.hpp.

Referenced by bytes_read(), and is_read_complete().

std::size_t twesnothd_connection::bytes_to_read_
private

Definition at line 139 of file wesnothd_connection.hpp.

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

std::size_t twesnothd_connection::bytes_to_write_
private

Definition at line 137 of file wesnothd_connection.hpp.

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

std::size_t twesnothd_connection::bytes_written_
private

Definition at line 138 of file wesnothd_connection.hpp.

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

bool twesnothd_connection::handshake_finished_
private

Definition at line 102 of file wesnothd_connection.hpp.

Referenced by handle_handshake(), and handshake_finished().

union { ... } twesnothd_connection::handshake_response_

Referenced by handshake().

boost::asio::io_service twesnothd_connection::io_service_
private

Definition at line 95 of file wesnothd_connection.hpp.

Referenced by poll().

boost::uint32_t twesnothd_connection::num

Definition at line 122 of file wesnothd_connection.hpp.

Referenced by is_read_complete().

boost::uint32_t twesnothd_connection::payload_size_
private

Definition at line 136 of file wesnothd_connection.hpp.

Referenced by send().

boost::asio::streambuf twesnothd_connection::read_buf_
private

Definition at line 104 of file wesnothd_connection.hpp.

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

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

Definition at line 134 of file wesnothd_connection.hpp.

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

resolver twesnothd_connection::resolver_
private

Definition at line 97 of file wesnothd_connection.hpp.

Referenced by twesnothd_connection().

std::list<boost::asio::streambuf> twesnothd_connection::send_queue_
private

Definition at line 133 of file wesnothd_connection.hpp.

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

socket twesnothd_connection::socket_
private

Definition at line 100 of file wesnothd_connection.hpp.

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


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