Lines 42-51
namespace {
Link Here
|
42 |
public: |
42 |
public: |
43 |
using ServerList = std::vector<std::pair<boost::asio::ip::address, std::string>>; |
43 |
using ServerList = std::vector<std::pair<boost::asio::ip::address, std::string>>; |
44 |
|
44 |
|
45 |
ServerDiscoverer(boost::asio::io_service& io_service) : |
45 |
ServerDiscoverer(boost::asio::io_context& io_context) : |
46 |
m_io_service(&io_service), |
46 |
m_io_context(&io_context), |
47 |
m_timer(io_service), |
47 |
m_timer(io_context), |
48 |
m_socket(io_service), |
48 |
m_socket(io_context), |
49 |
m_recv_buf(), |
49 |
m_recv_buf(), |
50 |
m_receive_successful(false), |
50 |
m_receive_successful(false), |
51 |
m_server_name() |
51 |
m_server_name() |
Lines 56-62
namespace {
Link Here
|
56 |
|
56 |
|
57 |
void DiscoverServers() { |
57 |
void DiscoverServers() { |
58 |
using namespace boost::asio::ip; |
58 |
using namespace boost::asio::ip; |
59 |
udp::resolver resolver(*m_io_service); |
59 |
udp::resolver resolver(*m_io_context); |
60 |
udp::resolver::query query(udp::v4(), "255.255.255.255", |
60 |
udp::resolver::query query(udp::v4(), "255.255.255.255", |
61 |
std::to_string(Networking::DiscoveryPort()), |
61 |
std::to_string(Networking::DiscoveryPort()), |
62 |
resolver_query_base::address_configured | |
62 |
resolver_query_base::address_configured | |
Lines 81-88
namespace {
Link Here
|
81 |
boost::asio::placeholders::bytes_transferred)); |
81 |
boost::asio::placeholders::bytes_transferred)); |
82 |
m_timer.expires_from_now(std::chrono::seconds(2)); |
82 |
m_timer.expires_from_now(std::chrono::seconds(2)); |
83 |
m_timer.async_wait(boost::bind(&ServerDiscoverer::CloseSocket, this)); |
83 |
m_timer.async_wait(boost::bind(&ServerDiscoverer::CloseSocket, this)); |
84 |
m_io_service->run(); |
84 |
m_io_context->run(); |
85 |
m_io_service->reset(); |
85 |
m_io_context->reset(); |
86 |
if (m_receive_successful) { |
86 |
if (m_receive_successful) { |
87 |
boost::asio::ip::address address = m_server_name == "localhost" ? |
87 |
boost::asio::ip::address address = m_server_name == "localhost" ? |
88 |
boost::asio::ip::address::from_string("127.0.0.1") : |
88 |
boost::asio::ip::address::from_string("127.0.0.1") : |
Lines 121-127
namespace {
Link Here
|
121 |
void CloseSocket() |
121 |
void CloseSocket() |
122 |
{ m_socket.close(); } |
122 |
{ m_socket.close(); } |
123 |
|
123 |
|
124 |
boost::asio::io_service* m_io_service; |
124 |
boost::asio::io_context* m_io_context; |
125 |
boost::asio::high_resolution_timer m_timer; |
125 |
boost::asio::high_resolution_timer m_timer; |
126 |
boost::asio::ip::udp::socket m_socket; |
126 |
boost::asio::ip::udp::socket m_socket; |
127 |
|
127 |
|
Lines 233-239
class ClientNetworking::Impl {
Link Here
|
233 |
int m_host_player_id; |
233 |
int m_host_player_id; |
234 |
Networking::AuthRoles m_roles; |
234 |
Networking::AuthRoles m_roles; |
235 |
|
235 |
|
236 |
boost::asio::io_service m_io_service; |
236 |
boost::asio::io_context m_io_context; |
237 |
boost::asio::ip::tcp::socket m_socket; |
237 |
boost::asio::ip::tcp::socket m_socket; |
238 |
|
238 |
|
239 |
// m_mutex guards m_incoming_message, m_rx_connected and m_tx_connected which are written by |
239 |
// m_mutex guards m_incoming_message, m_rx_connected and m_tx_connected which are written by |
Lines 262-269
class ClientNetworking::Impl {
Link Here
|
262 |
ClientNetworking::Impl::Impl() : |
262 |
ClientNetworking::Impl::Impl() : |
263 |
m_player_id(Networking::INVALID_PLAYER_ID), |
263 |
m_player_id(Networking::INVALID_PLAYER_ID), |
264 |
m_host_player_id(Networking::INVALID_PLAYER_ID), |
264 |
m_host_player_id(Networking::INVALID_PLAYER_ID), |
265 |
m_io_service(), |
265 |
m_io_context(), |
266 |
m_socket(m_io_service), |
266 |
m_socket(m_io_context), |
267 |
m_rx_connected(false), |
267 |
m_rx_connected(false), |
268 |
m_tx_connected(false), |
268 |
m_tx_connected(false), |
269 |
m_incoming_messages(m_mutex) |
269 |
m_incoming_messages(m_mutex) |
Lines 302-308
bool ClientNetworking::Impl::HasAuthRole(Networking::RoleType role) const
Link Here
|
302 |
ClientNetworking::ServerNames ClientNetworking::Impl::DiscoverLANServerNames() { |
302 |
ClientNetworking::ServerNames ClientNetworking::Impl::DiscoverLANServerNames() { |
303 |
if (!IsConnected()) |
303 |
if (!IsConnected()) |
304 |
return ServerNames(); |
304 |
return ServerNames(); |
305 |
ServerDiscoverer discoverer(m_io_service); |
305 |
ServerDiscoverer discoverer(m_io_context); |
306 |
discoverer.DiscoverServers(); |
306 |
discoverer.DiscoverServers(); |
307 |
ServerNames names; |
307 |
ServerNames names; |
308 |
for (const auto& server : discoverer.Servers()) { |
308 |
for (const auto& server : discoverer.Servers()) { |
Lines 325-331
bool ClientNetworking::Impl::ConnectToServer(
Link Here
|
325 |
auto deadline = start_time + timeout; |
325 |
auto deadline = start_time + timeout; |
326 |
|
326 |
|
327 |
using namespace boost::asio::ip; |
327 |
using namespace boost::asio::ip; |
328 |
tcp::resolver resolver(m_io_service); |
328 |
tcp::resolver resolver(m_io_context); |
329 |
tcp::resolver::query query(ip_address, |
329 |
tcp::resolver::query query(ip_address, |
330 |
std::to_string(Networking::MessagePort()), |
330 |
std::to_string(Networking::MessagePort()), |
331 |
boost::asio::ip::resolver_query_base::numeric_service); |
331 |
boost::asio::ip::resolver_query_base::numeric_service); |
Lines 347-354
bool ClientNetworking::Impl::ConnectToServer(
Link Here
|
347 |
m_socket.async_connect(*it, boost::bind(&ClientNetworking::Impl::HandleConnection, this, |
347 |
m_socket.async_connect(*it, boost::bind(&ClientNetworking::Impl::HandleConnection, this, |
348 |
&it, |
348 |
&it, |
349 |
boost::asio::placeholders::error)); |
349 |
boost::asio::placeholders::error)); |
350 |
m_io_service.run(); |
350 |
m_io_context.run(); |
351 |
m_io_service.reset(); |
351 |
m_io_context.reset(); |
352 |
|
352 |
|
353 |
auto connection_time = Clock::now() - start_time; |
353 |
auto connection_time = Clock::now() - start_time; |
354 |
|
354 |
|
Lines 435-441
void ClientNetworking::Impl::DisconnectFromServer() {
Link Here
|
435 |
} |
435 |
} |
436 |
|
436 |
|
437 |
if (is_open) |
437 |
if (is_open) |
438 |
m_io_service.post(boost::bind(&ClientNetworking::Impl::DisconnectFromServerImpl, this)); |
438 |
m_io_context.post(boost::bind(&ClientNetworking::Impl::DisconnectFromServerImpl, this)); |
439 |
} |
439 |
} |
440 |
|
440 |
|
441 |
void ClientNetworking::Impl::SetPlayerID(int player_id) { |
441 |
void ClientNetworking::Impl::SetPlayerID(int player_id) { |
Lines 455-461
void ClientNetworking::Impl::SendMessage(const Message& message) {
Link Here
|
455 |
return; |
455 |
return; |
456 |
} |
456 |
} |
457 |
TraceLogger(network) << "ClientNetworking::SendMessage() : sending message " << message; |
457 |
TraceLogger(network) << "ClientNetworking::SendMessage() : sending message " << message; |
458 |
m_io_service.post(boost::bind(&ClientNetworking::Impl::SendMessageImpl, this, message)); |
458 |
m_io_context.post(boost::bind(&ClientNetworking::Impl::SendMessageImpl, this, message)); |
459 |
} |
459 |
} |
460 |
|
460 |
|
461 |
boost::optional<Message> ClientNetworking::Impl::GetMessage() { |
461 |
boost::optional<Message> ClientNetworking::Impl::GetMessage() { |
Lines 504-515
void ClientNetworking::Impl::NetworkingThread(const std::shared_ptr<const Client
Link Here
|
504 |
if (!m_outgoing_messages.empty()) |
504 |
if (!m_outgoing_messages.empty()) |
505 |
AsyncWriteMessage(); |
505 |
AsyncWriteMessage(); |
506 |
AsyncReadMessage(protect_from_destruction_in_other_thread); |
506 |
AsyncReadMessage(protect_from_destruction_in_other_thread); |
507 |
m_io_service.run(); |
507 |
m_io_context.run(); |
508 |
} catch (const boost::system::system_error& error) { |
508 |
} catch (const boost::system::system_error& error) { |
509 |
HandleException(error); |
509 |
HandleException(error); |
510 |
} |
510 |
} |
511 |
m_outgoing_messages.clear(); |
511 |
m_outgoing_messages.clear(); |
512 |
m_io_service.reset(); |
512 |
m_io_context.reset(); |
513 |
{ // Mutex scope |
513 |
{ // Mutex scope |
514 |
boost::mutex::scoped_lock lock(m_mutex); |
514 |
boost::mutex::scoped_lock lock(m_mutex); |
515 |
m_rx_connected = false; |
515 |
m_rx_connected = false; |