From c61bd57286558d73c085458bf0205efc90a0d598 Mon Sep 17 00:00:00 2001 From: fantasy-peak <1356346239@qq.com> Date: Tue, 21 May 2024 12:40:37 +0800 Subject: [PATCH] Fix bug --- .github/workflows/ubuntu-gcc13.yaml | 10 ++++----- README.md | 1 - out/bi_web/include/fantasy.hpp | 32 ++++++++++++++--------------- out/bi_web/include/impl/utils.h | 8 ++++++-- out/include/fantasy.hpp | 32 ++++++++++++++--------------- out/include/impl/utils.h | 8 ++++++-- template/cpp/bi.inja | 19 ++++++++--------- template/cpp/bi_stream.inja | 13 ++++++------ template/cpp/impl/utils.inja | 8 ++++++-- 9 files changed, 70 insertions(+), 61 deletions(-) diff --git a/.github/workflows/ubuntu-gcc13.yaml b/.github/workflows/ubuntu-gcc13.yaml index 208ca13..d9ce7c3 100644 --- a/.github/workflows/ubuntu-gcc13.yaml +++ b/.github/workflows/ubuntu-gcc13.yaml @@ -1,4 +1,4 @@ -name: ubuntu-gcc13 +name: ubuntu-gcc14 on: push: @@ -18,7 +18,7 @@ jobs: - name: Installation run: | sudo apt-get update - sudo apt-get install -y valgrind libgl1-mesa-dev libglu1-mesa-dev p7zip gobjc g++-13 wget sudo + sudo apt-get install -y valgrind libgl1-mesa-dev libglu1-mesa-dev p7zip gobjc g++-14 wget sudo - uses: xmake-io/github-action-setup-xmake@v1 with: @@ -29,9 +29,9 @@ jobs: - name: build run: | export XMAKE_ROOT="y" - g++-13 -v - export CXX=g++-13 - export CC=gcc-13 + g++-14 -v + export CXX=g++-14 + export CC=gcc-14 xmake build -y xmake install -o . diff --git a/README.md b/README.md index 33694c6..b398be6 100644 --- a/README.md +++ b/README.md @@ -136,4 +136,3 @@ Stream: ## Contact * **Issue** - You are very welcome to post questions to [issues](https://github.com/fantasy-peak/frpc/issues) list. - diff --git a/out/bi_web/include/fantasy.hpp b/out/bi_web/include/fantasy.hpp index dfe1dfa..1136036 100644 --- a/out/bi_web/include/fantasy.hpp +++ b/out/bi_web/include/fantasy.hpp @@ -114,7 +114,7 @@ class HelloWorldClient final { frpc::DateTime date_time, std::function< void(std::string, Info, uint64_t, std::optional)> cb) { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto snd_bufs = makeRequestPacket( req_id, @@ -140,7 +140,7 @@ class HelloWorldClient final { void(std::string, Info, uint64_t, std::optional)> cb, const std::chrono::milliseconds& timeout, std::function timeout_cb) { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto snd_bufs = makeRequestPacket( req_id, @@ -393,7 +393,8 @@ class HelloWorldClient final { private: template - std::vector makeRequestPacket(uint64_t req_id, T&& t) { + std::vector makeRequestPacket(const std::string& req_id, + T&& t) { auto header = std::make_tuple(req_id, type); auto buffer = frpc::pack(header); auto packet = frpc::pack(std::forward(t)); @@ -404,7 +405,7 @@ class HelloWorldClient final { return snd_bufs; } - void callTimeoutCallback(uint64_t req_id) { + void callTimeoutCallback(const std::string& req_id) { std::unique_lock lk(m_mtx); if (m_timeout_cb.find(req_id) == m_timeout_cb.end()) return; @@ -422,7 +423,7 @@ class HelloWorldClient final { } try { using FrpcHeader = - std::tuple; + std::tuple; auto [req_id, req_type] = frpc::unpack(recv_bufs[0].data(), recv_bufs[0].size()); @@ -467,9 +468,8 @@ class HelloWorldClient final { std::unique_ptr m_channel; std::function m_error; std::mutex m_mtx; - std::unordered_map m_cb; - std::unordered_map> m_timeout_cb; - std::atomic_uint64_t m_req_id{0}; + std::unordered_map m_cb; + std::unordered_map> m_timeout_cb; }; struct HelloWorldServerHandler { @@ -663,7 +663,7 @@ class HelloWorldServer final { } try { using FrpcHeader = - std::tuple; + std::tuple; [[maybe_unused]] auto [req_id, req_type] = frpc::unpack(recv_bufs[1].data(), recv_bufs[1].size()); @@ -1304,7 +1304,7 @@ class StreamClient final { } auto hello_world() { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto header = std::make_tuple(req_id, StreamClientStreamServer::hello_world); @@ -1383,7 +1383,7 @@ class StreamClient final { } try { using FrpcHeader = - std::tuple; + std::tuple; auto [req_id, req_type, is_close] = frpc::unpack(recv_bufs[0].data(), recv_bufs[0].size()); @@ -1424,9 +1424,8 @@ class StreamClient final { std::unique_ptr m_channel; std::function m_error; std::mutex m_mtx; - std::unordered_map m_cb; - std::unordered_map> m_close_cb; - std::atomic_uint64_t m_req_id{0}; + std::unordered_map m_cb; + std::unordered_map> m_close_cb; std::unique_ptr m_pool_ptr; }; @@ -1570,7 +1569,8 @@ class StreamServer final { return; } try { - using FrpcHeader = std::tuple; + using FrpcHeader = + std::tuple; auto [req_id, req_type] = frpc::unpack(recv_bufs[1].data(), recv_bufs[1].size()); @@ -1696,7 +1696,7 @@ class StreamServer final { std::unique_ptr m_channel; std::mutex m_mtx; std::unique_ptr m_pool_ptr; - std::unordered_map m_channel_mapping; + std::unordered_map m_channel_mapping; }; #endif diff --git a/out/bi_web/include/impl/utils.h b/out/bi_web/include/impl/utils.h index eb7f86a..619d4a4 100644 --- a/out/bi_web/include/impl/utils.h +++ b/out/bi_web/include/impl/utils.h @@ -65,12 +65,16 @@ struct ChannelConfig { std::size_t channel_size{50000}; }; -inline std::string uniqueAddr() { +inline std::string createUuid() { uuid_t uuid; char s[37]; uuid_generate_random(uuid); uuid_unparse(uuid, s); - return "inproc://" + std::string(s); + return std::string(s); +} + +inline std::string uniqueAddr() { + return "inproc://" + createUuid(); } template diff --git a/out/include/fantasy.hpp b/out/include/fantasy.hpp index dfe1dfa..1136036 100644 --- a/out/include/fantasy.hpp +++ b/out/include/fantasy.hpp @@ -114,7 +114,7 @@ class HelloWorldClient final { frpc::DateTime date_time, std::function< void(std::string, Info, uint64_t, std::optional)> cb) { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto snd_bufs = makeRequestPacket( req_id, @@ -140,7 +140,7 @@ class HelloWorldClient final { void(std::string, Info, uint64_t, std::optional)> cb, const std::chrono::milliseconds& timeout, std::function timeout_cb) { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto snd_bufs = makeRequestPacket( req_id, @@ -393,7 +393,8 @@ class HelloWorldClient final { private: template - std::vector makeRequestPacket(uint64_t req_id, T&& t) { + std::vector makeRequestPacket(const std::string& req_id, + T&& t) { auto header = std::make_tuple(req_id, type); auto buffer = frpc::pack(header); auto packet = frpc::pack(std::forward(t)); @@ -404,7 +405,7 @@ class HelloWorldClient final { return snd_bufs; } - void callTimeoutCallback(uint64_t req_id) { + void callTimeoutCallback(const std::string& req_id) { std::unique_lock lk(m_mtx); if (m_timeout_cb.find(req_id) == m_timeout_cb.end()) return; @@ -422,7 +423,7 @@ class HelloWorldClient final { } try { using FrpcHeader = - std::tuple; + std::tuple; auto [req_id, req_type] = frpc::unpack(recv_bufs[0].data(), recv_bufs[0].size()); @@ -467,9 +468,8 @@ class HelloWorldClient final { std::unique_ptr m_channel; std::function m_error; std::mutex m_mtx; - std::unordered_map m_cb; - std::unordered_map> m_timeout_cb; - std::atomic_uint64_t m_req_id{0}; + std::unordered_map m_cb; + std::unordered_map> m_timeout_cb; }; struct HelloWorldServerHandler { @@ -663,7 +663,7 @@ class HelloWorldServer final { } try { using FrpcHeader = - std::tuple; + std::tuple; [[maybe_unused]] auto [req_id, req_type] = frpc::unpack(recv_bufs[1].data(), recv_bufs[1].size()); @@ -1304,7 +1304,7 @@ class StreamClient final { } auto hello_world() { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto header = std::make_tuple(req_id, StreamClientStreamServer::hello_world); @@ -1383,7 +1383,7 @@ class StreamClient final { } try { using FrpcHeader = - std::tuple; + std::tuple; auto [req_id, req_type, is_close] = frpc::unpack(recv_bufs[0].data(), recv_bufs[0].size()); @@ -1424,9 +1424,8 @@ class StreamClient final { std::unique_ptr m_channel; std::function m_error; std::mutex m_mtx; - std::unordered_map m_cb; - std::unordered_map> m_close_cb; - std::atomic_uint64_t m_req_id{0}; + std::unordered_map m_cb; + std::unordered_map> m_close_cb; std::unique_ptr m_pool_ptr; }; @@ -1570,7 +1569,8 @@ class StreamServer final { return; } try { - using FrpcHeader = std::tuple; + using FrpcHeader = + std::tuple; auto [req_id, req_type] = frpc::unpack(recv_bufs[1].data(), recv_bufs[1].size()); @@ -1696,7 +1696,7 @@ class StreamServer final { std::unique_ptr m_channel; std::mutex m_mtx; std::unique_ptr m_pool_ptr; - std::unordered_map m_channel_mapping; + std::unordered_map m_channel_mapping; }; #endif diff --git a/out/include/impl/utils.h b/out/include/impl/utils.h index eb7f86a..619d4a4 100644 --- a/out/include/impl/utils.h +++ b/out/include/impl/utils.h @@ -65,12 +65,16 @@ struct ChannelConfig { std::size_t channel_size{50000}; }; -inline std::string uniqueAddr() { +inline std::string createUuid() { uuid_t uuid; char s[37]; uuid_generate_random(uuid); uuid_unparse(uuid, s); - return "inproc://" + std::string(s); + return std::string(s); +} + +inline std::string uniqueAddr() { + return "inproc://" + createUuid(); } template diff --git a/template/cpp/bi.inja b/template/cpp/bi.inja index d7a830c..e3aba4c 100644 --- a/template/cpp/bi.inja +++ b/template/cpp/bi.inja @@ -54,7 +54,7 @@ public: {% for func in value.definitions %} void {{func.func_name}}({{_format_args(func.inputs)}}, std::function cb) { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto snd_bufs = makeRequestPacket<{{value.caller}}{{value.callee}}::{{func.func_name}}>( req_id, std::make_tuple({{_format_args_name_and_move(func.inputs)}})); @@ -69,7 +69,7 @@ public: std::function cb, const std::chrono::milliseconds& timeout, std::function timeout_cb) { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto snd_bufs = makeRequestPacket<{{value.caller}}{{value.callee}}::{{func.func_name}}>( req_id, std::make_tuple({{_format_args_name_and_move(func.inputs)}})); @@ -176,7 +176,7 @@ public: private: template <{{value.caller}}{{value.callee}} type, typename T> - std::vector makeRequestPacket(uint64_t req_id, T&& t) { + std::vector makeRequestPacket(const std::string& req_id, T&& t) { auto header = std::make_tuple(req_id, type); auto buffer = frpc::pack(header); auto packet = frpc::pack(std::forward(t)); @@ -187,7 +187,7 @@ private: return snd_bufs; } - void callTimeoutCallback(uint64_t req_id) { + void callTimeoutCallback(const std::string& req_id) { std::unique_lock lk(m_mtx); if (m_timeout_cb.find(req_id) == m_timeout_cb.end()) return; @@ -204,7 +204,7 @@ private: return; } try { - using FrpcHeader = std::tuple; + using FrpcHeader = std::tuple; auto [req_id, req_type] = frpc::unpack(recv_bufs[0].data(), recv_bufs[0].size()); std::unique_lock lk(m_mtx); if (m_cb.find(req_id) == m_cb.end()) @@ -237,10 +237,9 @@ private: std::unique_ptr m_channel; std::function m_error; std::mutex m_mtx; - std::unordered_map m_cb; - std::unordered_map> m_timeout_cb; - std::atomic_uint64_t m_req_id{0}; -}; + std::unordered_map m_cb; + std::unordered_map> m_timeout_cb; +}; struct {{value.callee}}Handler { {% for func in value.definitions %} @@ -372,7 +371,7 @@ private: return; } try { - using FrpcHeader = std::tuple; + using FrpcHeader = std::tuple; [[maybe_unused]] auto [req_id, req_type] = frpc::unpack(recv_bufs[1].data(), recv_bufs[1].size()); switch(req_type) { {% for func in value.definitions %} diff --git a/template/cpp/bi_stream.inja b/template/cpp/bi_stream.inja index d3ba804..5dfd58c 100644 --- a/template/cpp/bi_stream.inja +++ b/template/cpp/bi_stream.inja @@ -71,7 +71,7 @@ public: {% for func in value.definitions %} auto {{func.func_name}}() { - auto req_id = m_req_id.fetch_add(1); + auto req_id = frpc::createUuid(); auto header = std::make_tuple(req_id, {{value.caller}}{{value.callee}}::{{func.func_name}}); auto buffer = frpc::pack(header); @@ -132,7 +132,7 @@ private: return; } try { - using FrpcHeader = std::tuple; + using FrpcHeader = std::tuple; auto [req_id, req_type, is_close] = frpc::unpack(recv_bufs[0].data(), recv_bufs[0].size()); if (is_close) { std::unique_lock lk(m_mtx); @@ -171,9 +171,8 @@ private: std::unique_ptr m_channel; std::function m_error; std::mutex m_mtx; - std::unordered_map m_cb; - std::unordered_map> m_close_cb; - std::atomic_uint64_t m_req_id{0}; + std::unordered_map m_cb; + std::unordered_map> m_close_cb; std::unique_ptr m_pool_ptr; }; @@ -284,7 +283,7 @@ private: return; } try { - using FrpcHeader = std::tuple; + using FrpcHeader = std::tuple; auto [req_id, req_type] = frpc::unpack(recv_bufs[1].data(), recv_bufs[1].size()); switch(req_type) { {% for func in value.definitions %} @@ -375,7 +374,7 @@ private: std::unique_ptr m_channel; std::mutex m_mtx; std::unique_ptr m_pool_ptr; - std::unordered_map m_channel_mapping; + std::unordered_map m_channel_mapping; }; #endif diff --git a/template/cpp/impl/utils.inja b/template/cpp/impl/utils.inja index f3b7251..0123c3e 100644 --- a/template/cpp/impl/utils.inja +++ b/template/cpp/impl/utils.inja @@ -65,12 +65,16 @@ struct ChannelConfig { std::size_t channel_size{50000}; }; -inline std::string uniqueAddr() { +inline std::string createUuid() { uuid_t uuid; char s[37]; uuid_generate_random(uuid); uuid_unparse(uuid, s); - return "inproc://" + std::string(s); + return std::string(s); +} + +inline std::string uniqueAddr() { + return "inproc://" + createUuid(); } template