Fix Windows compile error

This commit is contained in:
badaix 2025-01-27 10:52:28 +01:00
parent a407e68df6
commit 29e267532a
2 changed files with 11 additions and 5 deletions

View file

@ -399,6 +399,9 @@ ClientConnectionWs::~ClientConnectionWs()
tcp_websocket& ClientConnectionWs::getWs() tcp_websocket& ClientConnectionWs::getWs()
{ {
// Looks like the websocket must be recreated after disconnect:
// https://github.com/boostorg/beast/issues/2409#issuecomment-1103685782
std::lock_guard lock(ws_mutex_); std::lock_guard lock(ws_mutex_);
if (tcp_ws_.has_value()) if (tcp_ws_.has_value())
return tcp_ws_.value(); return tcp_ws_.value();
@ -524,6 +527,9 @@ ClientConnectionWss::ClientConnectionWss(boost::asio::io_context& io_context, bo
ssl_websocket& ClientConnectionWss::getWs() ssl_websocket& ClientConnectionWss::getWs()
{ {
// Looks like the websocket must be recreated after disconnect:
// https://github.com/boostorg/beast/issues/2409#issuecomment-1103685782
std::lock_guard lock(ws_mutex_); std::lock_guard lock(ws_mutex_);
if (ssl_ws_.has_value()) if (ssl_ws_.has_value())
return ssl_ws_.value(); return ssl_ws_.value();
@ -586,7 +592,7 @@ std::string ClientConnectionWss::getMacAddress()
#ifndef WINDOWS #ifndef WINDOWS
::getMacAddress(getWs().next_layer().lowest_layer().native_handle()); ::getMacAddress(getWs().next_layer().lowest_layer().native_handle());
#else #else
::getMacAddress(ssl_ws_.next_layer().lowest_layer().local_endpoint().address().to_string()); ::getMacAddress(getWs().next_layer().lowest_layer().local_endpoint().address().to_string());
#endif #endif
if (mac.empty()) if (mac.empty())
mac = "00:00:00:00:00:00"; mac = "00:00:00:00:00:00";
@ -641,12 +647,12 @@ boost::system::error_code ClientConnectionWss::doConnect(boost::asio::ip::basic_
{ {
boost::system::error_code ec; boost::system::error_code ec;
getWs().binary(true); getWs().binary(true);
beast::get_lowest_layer(*ssl_ws_).connect(endpoint, ec); beast::get_lowest_layer(getWs()).connect(endpoint, ec);
if (ec.failed()) if (ec.failed())
return ec; return ec;
// Set a timeout on the operation // Set a timeout on the operation
// beast::get_lowest_layer(ssl_ws_).expires_after(std::chrono::seconds(30)); // beast::get_lowest_layer(getWs()).expires_after(std::chrono::seconds(30));
// Set suggested timeout settings for the websocket // Set suggested timeout settings for the websocket
getWs().set_option(websocket::stream_base::timeout::suggested(beast::role_type::client)); getWs().set_option(websocket::stream_base::timeout::suggested(beast::role_type::client));

View file

@ -88,9 +88,9 @@ Controller::Controller(boost::asio::io_context& io_context, const ClientSettings
LOG(WARNING, LOG_TAG) << "Failed to load system certificates: " << ec << "\n"; LOG(WARNING, LOG_TAG) << "Failed to load system certificates: " << ec << "\n";
if (!settings.server.certificate->empty()) if (!settings.server.certificate->empty())
{ {
ssl_context_.load_verify_file(settings.server.certificate.value(), ec); ssl_context_.load_verify_file(settings.server.certificate.value().string(), ec);
if (ec.failed()) if (ec.failed())
throw SnapException("Failed to load certificate: " + settings.server.certificate.value().native() + ": " + ec.message()); throw SnapException("Failed to load certificate: " + settings.server.certificate.value().string() + ": " + ec.message());
} }
} }
} }