concurrencpp 换成asio协程

This commit is contained in:
2026-06-29 08:50:10 +08:00
parent c683038d3a
commit cd446b7ca8
11 changed files with 335 additions and 315 deletions
+6 -23
View File
@@ -1,6 +1,5 @@
#include "Local_Server/Data_Feed/Data_Feed.h"
#include "../server/Global.h"
bool Data_Feed::registered() {
auto all_feed = Global::instance()->mode_acs.data_feed_config.map.list();
for (auto& item : all_feed) {
@@ -10,24 +9,20 @@ bool Data_Feed::registered() {
}
return false;
}
concurrencpp::result<void> Data_Feed_UDP_Server::handle_in_loop_coro() {
asio::awaitable<void> Data_Feed_UDP_Server::handle_in_loop_coro() {
co_await svr.tick_coro();
co_return;
}
concurrencpp::result<void> Data_Feed_UDP_Server::send_coro(const std::string& data) {
asio::awaitable<void> Data_Feed_UDP_Server::send_coro(const std::string& data) {
co_await svr.write_to_all_clients_coro(data);
co_return;
}
concurrencpp::result<void> Data_Feed_UDP_Server::_open() {
asio::awaitable<void> Data_Feed_UDP_Server::_open() {
svr.set_bind_address("0.0.0.0", port);
svr.create();
server_logger->c_debug({}, {}, to_string() + "开启!");
co_return;
}
JSON Data_feed_Config::get_feed(const std::string& key) {
auto ret = map.get(key);
if (ret.has_value()) {
@@ -36,8 +31,7 @@ JSON Data_feed_Config::get_feed(const std::string& key) {
}
return {nullptr};
}
void Data_feed_Config::server(Global* g) {
void Data_feed_Config::server(Global *g) {
auto& svr = g->svr;
auto& api = g->api;
std::string name = "data_feed";
@@ -86,13 +80,10 @@ void Data_feed_Config::server(Global* g) {
svr.Post(api + svr.update + name, [g, this](HTTP_Param) {
CHECK_JSON_PARAM
HTTP_REQUIRE_VALUE(key, params.try_get_string("key"))
HTTP_REQUIRE_VALUE(t, map.get(key))
HTTP_REQUIRE_VALUE(df, map.get(key))
// 直接关闭
// t->close();
t->from_json(&params);
// if (t->enable) {
// t->check_and_open();
// }
df->from_json(&params);
Global::save();
g->mode_acs.source_feed_relation_config.set_need_refresh();
});
@@ -104,10 +95,6 @@ void Data_feed_Config::server(Global* g) {
auto df = create_data_feed_from_type(t);
df->from_json(data);
HTTP_REQUIRE_VALUE(enable, data->try_get_bool("enable"))
// if (enable)
// {
// df->check_and_open();
// }
HTTP_REQUIRE_TRUE(map.insert(index, df), "index")
res->setBody(warp(to_json()).to_json_string());
Global::save();
@@ -140,7 +127,6 @@ void Data_feed_Config::server(Global* g) {
g->mode_acs.source_feed_relation_config.set_need_refresh();
});
}
void BIN_Msg_Buffer::push(const std::string& msg) {
auto output_packet_size =
Global::instance()->mode_acs.data_feed_config.packet_byte_size.load();
@@ -156,7 +142,6 @@ void BIN_Msg_Buffer::push(const std::string& msg) {
msg_list_cache.back()->append(msg);
}
}
const std::vector<std::string*>& BIN_Msg_Buffer::get_all() {
std::lock_guard<std::mutex> g(mtx);
std::swap(msg_list_cache, msg_list);
@@ -165,12 +150,10 @@ const std::vector<std::string*>& BIN_Msg_Buffer::get_all() {
mode_other_msg_num = 0;
return msg_list;
}
BIN_Msg_Buffer::BIN_Msg_Buffer() {
msg_list_cache.reserve(8 * 1024);
msg_list.reserve(8 * 1024);
}
Psc::JSON BIN_Msg_Buffer::state_json() {
auto output_packet_size =
Global::instance()->mode_acs.data_feed_config.packet_byte_size.load();