17 #include <boost/ref.hpp>
18 #include <boost/cstdint.hpp>
19 #include <boost/version.hpp>
25 #define DBG_NW LOG_STREAM(debug, log_network)
26 #define LOG_NW LOG_STREAM(info, log_network)
27 #define WRN_NW LOG_STREAM(warn, log_network)
28 #define ERR_NW LOG_STREAM(err, log_network)
30 using boost::system::system_error;
31 using boost::system::error_code;
35 , resolver_(io_service_)
36 , socket_(io_service_)
37 , handshake_finished_(false)
39 , handshake_response_()
50 LOG_NW <<
"Resolving hostname: " << host <<
'\n';
56 throw system_error(ec);
63 socket_.async_connect(*iterator, std::bind(
66 LOG_NW <<
"Connecting to " << iterator->endpoint().address() <<
'\n';
70 const boost::system::error_code& ec,
75 WRN_NW <<
"Failed to connect to " <<
76 iterator->endpoint().address() <<
": " <<
80 ERR_NW <<
"Tried all IPs. Giving up" << std::endl;
81 throw system_error(ec);
87 LOG_NW <<
"Connected to " << iterator->endpoint().address() <<
'\n';
95 boost::asio::async_write(
socket_,
97 [](
const error_code& ec, std::size_t) {
if (ec)
throw system_error(ec); }
99 boost::asio::async_read(
socket_,
108 throw system_error(ec);
129 boost::system::error_code ec;
132 WRN_NW <<
"Failed to cancel network operations: " << ec.message() << std::endl;
140 throw system_error(ec);
146 const boost::system::error_code& ec,
147 std::size_t bytes_transferred
150 DBG_NW <<
"Written " << bytes_transferred <<
" bytes.\n";
153 throw system_error(ec);
161 const boost::system::error_code& ec,
162 std::size_t bytes_transferred
166 throw system_error(ec);
169 if(bytes_transferred < 4) {
175 is.read(data_size.binary, 4);
186 const boost::system::error_code& ec,
187 std::size_t bytes_transferred
190 DBG_NW <<
"Read " << bytes_transferred <<
" bytes.\n";
192 if(ec && ec != boost::asio::error::eof)
193 throw system_error(ec);
205 size_t buf_size =
buf.size();
210 boost::asio::streambuf::const_buffers_type gzipped_data =
buf.data();
211 std::deque<boost::asio::const_buffer>
bufs(gzipped_data.begin(), gzipped_data.end());
232 catch (
const boost::system::system_error&
err) {
233 if (err.code() == boost::asio::error::operation_aborted)
235 throw error(err.code());
void write_gz(std::ostream &out, configr_of const &cfg)
std::size_t bytes_written_
void connect(resolver::iterator iterator)
std::size_t bytes_to_write_
void handle_handshake(const boost::system::error_code &ec)
void handle_resolve(const boost::system::error_code &ec, resolver::iterator iterator)
boost::uint32_t payload_size_
bool receive_data(config &result)
void cancel()
Run asio's event loop.
std::size_t is_read_complete(const boost::system::error_code &error, std::size_t bytes_transferred)
void read_gz(config &cfg, std::istream &file, abstract_validator *validator)
might throw a std::ios_base::failure especially a gzip_error
void send_data(const configr_of &request)
void handle_read(const boost::system::error_code &ec, std::size_t bytes_transferred)
std::size_t poll()
Handle all pending asynchonous events and return.
const GLuint GLenum const GLvoid * binary
GLenum GLuint GLsizei const char * buf
std::list< config > recv_queue_
boost::asio::io_service io_service_
void handle_write(const boost::system::error_code &ec, std::size_t bytes_transferred)
boost::asio::streambuf read_buf_
std::size_t bytes_to_read_
twesnothd_connection(const std::string &host, const std::string &service)
Constructor.
static lg::log_domain log_network("network")
std::list< boost::asio::streambuf > send_queue_
Standard logging facilities (interface).
wesnothd_connection_error error
void handle_connect(const boost::system::error_code &ec, resolver::iterator iterator)
A config object defines a single node in a WML file, with access to child nodes.
union twesnothd_connection::@26 handshake_response_
std::size_t is_write_complete(const boost::system::error_code &error, std::size_t bytes_transferred)
GLsizei const GLcharARB ** string