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)
32 using boost::system::system_error;
36 , resolver_(io_service_)
37 , socket_(io_service_)
41 , handshake_response_()
52 LOG_NW <<
"Resolving hostname: " << host <<
'\n';
56 const boost::system::error_code& ec,
61 throw system_error(ec);
68 socket_.async_connect(*iterator, std::bind(
71 LOG_NW <<
"Connecting to " << iterator->endpoint().address() <<
'\n';
75 const boost::system::error_code& ec,
80 WRN_NW <<
"Failed to connect to " <<
81 iterator->endpoint().address() <<
": " <<
85 ERR_NW <<
"Tried all IPs. Giving up" << std::endl;
86 throw system_error(ec);
90 LOG_NW <<
"Connected to " << iterator->endpoint().address() <<
'\n';
98 boost::asio::async_write(
socket_,
102 boost::asio::async_read(
socket_,
109 const boost::system::error_code& ec
113 throw system_error(ec);
127 boost::asio::streambuf::const_buffers_type gzipped_data =
write_buf_.data();
128 std::deque<boost::asio::const_buffer>
bufs(gzipped_data.begin(), gzipped_data.end());
143 boost::system::error_code ec;
146 WRN_NW <<
"Failed to cancel network operations: " << ec.message() << std::endl;
152 const boost::system::error_code& ec,
153 std::size_t bytes_transferred
157 throw system_error(ec);
159 #if BOOST_VERSION >= 103700
167 const boost::system::error_code& ec,
168 std::size_t bytes_transferred
171 DBG_NW <<
"Written " << bytes_transferred <<
" bytes.\n";
174 throw system_error(ec);
178 const boost::system::error_code& ec,
179 std::size_t bytes_transferred
183 throw system_error(ec);
186 if(bytes_transferred < 4) {
192 is.read(data_size.binary, 4);
198 #if BOOST_VERSION >= 103700
207 const boost::system::error_code& ec,
208 std::size_t bytes_transferred,
212 DBG_NW <<
"Read " << bytes_transferred <<
" bytes.\n";
216 if(ec && ec != boost::asio::error::eof)
217 throw system_error(ec);
void write_gz(std::ostream &out, configr_of const &cfg)
void handle_read(const boost::system::error_code &ec, std::size_t bytes_transferred, config &response)
boost::asio::streambuf write_buf_
connection(const std::string &host, const std::string &service)
Constructor.
std::size_t bytes_to_read_
boost::asio::streambuf read_buf_
void handle_connect(const boost::system::error_code &ec, resolver::iterator iterator)
std::size_t is_write_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
std::size_t bytes_to_write_
union network_asio::connection::@21 handshake_response_
const GLuint GLenum const GLvoid * binary
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 connect(resolver::iterator iterator)
static lg::log_domain log_network("network")
void transfer(const config &request, config &response)
boost::uint32_t payload_size_
boost::asio::io_service io_service_
std::size_t bytes_written_
Standard logging facilities (interface).
A config object defines a single node in a WML file, with access to child nodes.
void handle_resolve(const boost::system::error_code &ec, resolver::iterator iterator)
GLsizei const GLcharARB ** string
void handle_handshake(const boost::system::error_code &ec)