修复linux的编译

This commit is contained in:
2026-07-28 09:27:16 +08:00
parent 8835607ccd
commit 9d615e15b4
+33 -1
View File
@@ -1,9 +1,15 @@
#include "Global.h"
#include "Performance_Monitor.h"
#include <algorithm>
#include <asio/use_awaitable.hpp>
#if defined(ASIO_HAS_FILE)
#include <asio/random_access_file.hpp>
#include <asio/read_at.hpp>
#include <asio/use_awaitable.hpp>
#else
#include <asio/co_spawn.hpp>
#include <asio/thread_pool.hpp>
#include <fstream>
#endif
#include <cctype>
#include <cstdint>
#include <ctime>
@@ -222,12 +228,16 @@ public:
}
std::string content;
if (cache_request.include_body) {
#if defined(ASIO_HAS_FILE)
auto executor = co_await asio::this_coro::executor;
asio::random_access_file file(executor, path->generic_string(), asio::file_base::read_only);
content.resize(static_cast<std::size_t>(cache_info->size));
if (!content.empty()) {
co_await asio::async_read_at(file, 0, asio::buffer(content.data(), content.size()), asio::use_awaitable);
}
#else
content = co_await read_file_fallback(*path, static_cast<std::size_t>(cache_info->size));
#endif
}
co_return Tile_Load_Result{Tile_Load_Status::Ready, std::move(generic_path), std::move(content), std::move(content_type), *cache_info};
}
@@ -236,6 +246,28 @@ public:
}
private:
Tile_Path_Resolver resolver_;
#if !defined(ASIO_HAS_FILE)
static asio::thread_pool& tile_file_pool() {
static asio::thread_pool pool(4);
return pool;
}
static asio::awaitable<std::string> read_file_fallback(std::filesystem::path path, std::size_t size) {
co_return co_await asio::co_spawn(tile_file_pool(), [path = std::move(path), size]() -> asio::awaitable<std::string> {
std::ifstream file(path, std::ios::binary);
if (!file) {
throw std::runtime_error("failed to open tile file: " + path.generic_string());
}
std::string content(size, '\0');
if (!content.empty()) {
file.read(content.data(), static_cast<std::streamsize>(content.size()));
if (file.gcount() != static_cast<std::streamsize>(content.size())) {
throw std::runtime_error("failed to read complete tile file: " + path.generic_string());
}
}
co_return content;
}, asio::use_awaitable);
}
#endif
};
drogon::HttpResponsePtr make_tile_not_found_response(std::string_view request_path, bool include_body) {
auto response = drogon::HttpResponse::newHttpResponse();