24 #ifdef INADDR_BROADCAST
25 #undef INADDR_BROADCAST
37 #include <boost/asio/io_context.hpp>
38 #include <boost/asio/ip/tcp.hpp>
39 #include <boost/asio/streambuf.hpp>
40 #include <boost/asio/ssl.hpp>
42 #include <condition_variable>
98 return utils::holds_alternative<tls_socket>(
socket_);
147 typedef std::unique_ptr<boost::asio::ip::tcp::socket>
raw_socket;
148 typedef std::unique_ptr<boost::asio::ssl::stream<raw_socket::element_type>>
tls_socket;
162 using endpoint =
const boost::asio::ip::tcp::endpoint&;
175 void handle_write(
const boost::system::error_code& ec, std::size_t bytes_transferred);
178 void handle_read(
const boost::system::error_code& ec, std::size_t bytes_transferred);
A config object defines a single node in a WML file, with access to child nodes.
A class that represents a TCP/IP connection to the wesnothd server.
bool using_tls() const
True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tok...
boost::asio::ssl::context tls_context_
void handle_handshake(const boost::system::error_code &ec)
const boost::asio::ip::tcp::endpoint & endpoint
std::size_t bytes_to_read_
std::size_t bytes_to_read() const
bool has_data_received() const
void handle_connect(const boost::system::error_code &ec, endpoint endpoint)
void handle_resolve(const boost::system::error_code &ec, results_type results)
data_queue< std::unique_ptr< boost::asio::streambuf > > send_queue_
std::condition_variable recv_queue_lock_
std::size_t is_write_complete(const boost::system::error_code &error, std::size_t bytes_transferred)
uint32_t handshake_response_
std::size_t bytes_to_write() const
wesnothd_connection(const wesnothd_connection &)=delete
data_queue< config > recv_queue_
void wait_for_handshake()
Waits until the server handshake is complete.
boost::asio::io_context io_context_
wesnothd_connection & operator=(const wesnothd_connection &)=delete
std::mutex last_error_mutex_
bool receive_data(config &result)
Receives the next pending data pack from the server, if available.
void handle_write(const boost::system::error_code &ec, std::size_t bytes_transferred)
void send_data(const configr_of &request)
Queues the given data to be sent to the server.
void set_keepalive(int seconds)
std::mutex recv_queue_mutex_
resolver::results_type results_type
boost::asio::streambuf read_buf_
bool wait_and_receive_data(config &data)
Unlike receive_data, waits until data is available instead of returning immediately.
void handle_read(const boost::system::error_code &ec, std::size_t bytes_transferred)
std::size_t bytes_written() const
std::queue< T, std::list< T > > data_queue
boost::asio::ip::tcp::resolver resolver
void fallback_to_unencrypted()
std::size_t bytes_read() const
std::unique_ptr< boost::asio::ip::tcp::socket > raw_socket
boost::system::error_code last_error_
std::unique_ptr< boost::asio::ssl::stream< raw_socket::element_type > > tls_socket
std::thread worker_thread_
bool is_sending_data() const
std::promise< void > handshake_finished_
std::size_t bytes_to_write_
std::size_t bytes_written_
std::size_t is_read_complete(const boost::system::error_code &error, std::size_t bytes_transferred)
utils::variant< raw_socket, tls_socket > any_socket
An error occurred inside the underlying network communication code (boost asio) TODO: find a short na...