Skip to content

Commit

Permalink
Merge commit '43ceba7a0c25f86f07b8863d525d3f5f782331af' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Dec 16, 2024
2 parents 0d46e5a + 43ceba7 commit c58f6ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion airdcpp-webapi/web-server/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace webserver {

// CallbackWrapper is meant to ensure the lifetime of the timer
// (which necessary only if the timer is called from a class that can be deleted, such as sessions)
Timer(Callback&& aCallback, boost::asio::io_service& aIO, time_t aIntervalMillis, const CallbackWrapper& aWrapper) :
Timer(Callback&& aCallback, boost::asio::io_context& aIO, time_t aIntervalMillis, const CallbackWrapper& aWrapper) :
cb(std::move(aCallback)),
cbWrapper(aWrapper),
timer(aIO),
Expand Down
36 changes: 18 additions & 18 deletions airdcpp-webapi/web-server/WebServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace webserver {
WebServerManager::WebServerManager() :
ios(4),
tasks(4),
work(tasks)
wordGuardTasks(tasks.get_executor())
{
settingsManager = make_unique<WebServerSettings>(this);

Expand Down Expand Up @@ -141,10 +141,10 @@ namespace webserver {
return false;
}

ios.reset();
tasks.reset();
if (!has_io_service) {
has_io_service = initialize(errorF);
ios.restart();
tasks.restart();
if (!hasIOContext) {
hasIOContext = initialize(errorF);
}

if (!listen(errorF)) {
Expand All @@ -161,7 +161,7 @@ namespace webserver {
SettingsManager::getInstance()->setDefault(SettingsManager::HUB_MESSAGE_CACHE, 100);

try {
// initialize asio with our external io_service rather than an internal one
// initialize asio with our external io_context rather than an internal one
endpoint_plain.init_asio(&ios);
endpoint_tls.init_asio(&ios);
} catch (const websocketpp::exception& e) {
Expand Down Expand Up @@ -261,13 +261,13 @@ namespace webserver {
ios_threads = make_unique<boost::thread_group>();
task_threads = make_unique<boost::thread_group>();

// Start the ASIO io_service run loop running both endpoints
// Start the ASIO io_context run loop running both endpoints
for (int x = 0; x < WEBCFG(SERVER_THREADS).num(); ++x) {
ios_threads->create_thread(boost::bind(&boost::asio::io_service::run, &ios));
ios_threads->create_thread(boost::bind(&boost::asio::io_context::run, &ios));
}

for (int x = 0; x < std::max(WEBCFG(SERVER_THREADS).num() / 2, 1); ++x) {
task_threads->create_thread(boost::bind(&boost::asio::io_service::run, &tasks));
task_threads->create_thread(boost::bind(&boost::asio::io_context::run, &tasks));
}

// Add timers
Expand Down Expand Up @@ -357,7 +357,7 @@ namespace webserver {
}

void WebServerManager::addAsyncTask(Callback&& aCallback) noexcept {
tasks.post(std::move(aCallback));
boost::asio::post(tasks, std::move(aCallback));
}

void WebServerManager::log(const string& aMsg, LogMessage::Severity aSeverity) const noexcept {
Expand Down Expand Up @@ -420,23 +420,23 @@ namespace webserver {
}

string WebServerManager::resolveAddress(const string& aHostname, const string& aPort) noexcept {
auto ret = aHostname;

boost::asio::ip::tcp::resolver resolver(ios);
boost::asio::ip::tcp::resolver::query query(aHostname, aPort);

try {
boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
ret = iter->endpoint().address().to_string();
for (const auto& res: resolver.resolve(aHostname, aPort)) {
auto ret = res.endpoint().address().to_string();

if (res.endpoint().protocol() == boost::asio::ip::tcp::v6()) {
ret = "[" + ret + "]";
}

if (iter->endpoint().protocol() == boost::asio::ip::tcp::v6()) {
ret = "[" + ret + "]";
return ret;
}
} catch (const std::exception& e) {
log(e.what(), LogMessage::SEV_ERROR);
}

return ret;
return aHostname;
}

bool WebServerManager::hasValidServerConfig() const noexcept {
Expand Down
11 changes: 6 additions & 5 deletions airdcpp-webapi/web-server/WebServerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ namespace webserver {

mutable SharedMutex cs;

// set up an external io_service to run both endpoints on. This is not
// set up an external io_context to run both endpoints on. This is not
// strictly necessary, but simplifies thread management a bit.
boost::asio::io_service ios;
boost::asio::io_service tasks;
boost::asio::io_service::work work;
bool has_io_service = false;
boost::asio::io_context ios;
bool hasIOContext = false;

boost::asio::io_context tasks;
boost::asio::executor_work_guard<decltype(tasks.get_executor())> wordGuardTasks;

unique_ptr<WebUserManager> userManager;
unique_ptr<ExtensionManager> extManager;
Expand Down

0 comments on commit c58f6ae

Please sign in to comment.