Skip to content

Commit

Permalink
Improve internal implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasy-peak committed Aug 22, 2024
1 parent 2cb1c6c commit feb1953
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ubuntu-clang19
name: ubuntu-clang20

on:
push:
Expand All @@ -24,7 +24,7 @@ jobs:
sudo add-apt-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs) main"
sudo apt update
sudo apt list | grep clang
sudo apt install clang-19 -y
sudo apt install clang-20 -y
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt install -y gcc-13 g++-13
Expand All @@ -38,8 +38,8 @@ jobs:
run: |
export XMAKE_ROOT="y"
g++-13 -v
export CXX=clang++-19
export CC=clang-19
export CXX=clang++-20
export CC=clang-20
xmake build -y
xmake install -o .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frpc
*An rpc code generation framework for c++, It supports c++17/20/23*

[![](https://github.com/fantasy-peak/frpc/workflows/ubuntu-gcc13/badge.svg)](https://github.com/fantasy-peak/frpc/actions) [![](https://github.com/fantasy-peak/frpc/workflows/ubuntu-clang19/badge.svg)](https://github.com/fantasy-peak/frpc/actions) [![](https://img.shields.io/badge/language-C%2B%2B23-yellow.svg
[![](https://github.com/fantasy-peak/frpc/workflows/ubuntu-gcc13/badge.svg)](https://github.com/fantasy-peak/frpc/actions) [![](https://github.com/fantasy-peak/frpc/workflows/ubuntu-clang20/badge.svg)](https://github.com/fantasy-peak/frpc/actions) [![](https://img.shields.io/badge/language-C%2B%2B23-yellow.svg
)](https://en.wikipedia.org/wiki/C%2B%2B17)

## Support this repository:
Expand Down
64 changes: 59 additions & 5 deletions out/bi_web/include/fantasy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace fantasy {
class HelloWorldClient final {
public:
HelloWorldClient(const frpc::ChannelConfig& config,
std::function<void(std::string)> error)
const std::function<void(std::string)>& error)
: m_channel(std::make_unique<frpc::BiChannel>(
config,
error,
Expand All @@ -68,7 +68,7 @@ class HelloWorldClient final {
HelloWorldClient(const frpc::ChannelConfig& config,
const std::shared_ptr<zmq::context_t>& context_ptr,
const std::shared_ptr<zmq::socket_t>& socket_ptr,
std::function<void(std::string)> error)
const std::function<void(std::string)>& error)
: m_channel(std::make_unique<frpc::BiChannel>(
config,
context_ptr,
Expand All @@ -80,7 +80,7 @@ class HelloWorldClient final {

HelloWorldClient(const frpc::ChannelConfig& config,
const std::shared_ptr<zmq::context_t>& context_ptr,
std::function<void(std::string)> error)
const std::function<void(std::string)>& error)
: m_channel(std::make_unique<frpc::BiChannel>(
config,
context_ptr,
Expand All @@ -89,6 +89,11 @@ class HelloWorldClient final {
m_error(error) {
}

HelloWorldClient(const HelloWorldClient&) = delete;
HelloWorldClient& operator=(const HelloWorldClient&) = delete;
HelloWorldClient(HelloWorldClient&&) = delete;
HelloWorldClient& operator=(HelloWorldClient&&) = delete;

void start() {
m_channel->start();
}
Expand Down Expand Up @@ -178,7 +183,7 @@ class HelloWorldClient final {
std::optional<std::string> date,
frpc::DateTime date_time) mutable {
auto handler_ptr =
std::make_shared<Handler>(std::move(handler));
std::make_shared<Handler>(std::forward<Handler>(handler));
this->hello_world(
std::move(bank_info),
std::move(bank_name),
Expand Down Expand Up @@ -239,7 +244,7 @@ class HelloWorldClient final {
frpc::DateTime date_time,
const auto& timeout) mutable {
auto handler_ptr =
std::make_shared<Handler>(std::move(handler));
std::make_shared<Handler>(std::forward<Handler>(handler));
this->hello_world(
std::move(bank_info),
std::move(bank_name),
Expand Down Expand Up @@ -473,6 +478,9 @@ class HelloWorldClient final {
};

struct HelloWorldServerHandler {
HelloWorldServerHandler() = default;
virtual ~HelloWorldServerHandler() = default;

virtual void hello_world(
BankInfo bank_info,
std::string bank_name,
Expand All @@ -485,6 +493,9 @@ struct HelloWorldServerHandler {
};

struct AsioCoroHelloWorldServerHandler {
AsioCoroHelloWorldServerHandler() = default;
virtual ~AsioCoroHelloWorldServerHandler() = default;

#ifdef __cpp_impl_coroutine
virtual asio::awaitable<void> hello_world(
BankInfo bank_info,
Expand All @@ -509,6 +520,9 @@ struct AsioCoroHelloWorldServerHandler {
};

struct FrpcCoroHelloWorldServerHandler {
FrpcCoroHelloWorldServerHandler() = default;
virtual ~FrpcCoroHelloWorldServerHandler() = default;

#ifdef __cpp_impl_coroutine
virtual frpc::Task<void> hello_world(
BankInfo bank_info,
Expand Down Expand Up @@ -603,6 +617,11 @@ class HelloWorldServer final {
#endif
}

HelloWorldServer(const HelloWorldServer&) = delete;
HelloWorldServer& operator=(const HelloWorldServer&) = delete;
HelloWorldServer(HelloWorldServer&&) = delete;
HelloWorldServer& operator=(HelloWorldServer&&) = delete;

auto& socket() {
return m_channel->socket();
}
Expand Down Expand Up @@ -843,11 +862,17 @@ MSGPACK_ADD_ENUM(fantasy::HelloWorldSenderHelloWorldReceiver)
namespace fantasy {

struct HelloWorldReceiverHandler {
HelloWorldReceiverHandler() = default;
virtual ~HelloWorldReceiverHandler() = default;

virtual void hello_world(std::string in) noexcept = 0;
virtual void notice(int32_t in, std::string info) noexcept = 0;
};

struct AsioCoroHelloWorldReceiverHandler {
AsioCoroHelloWorldReceiverHandler() = default;
virtual ~AsioCoroHelloWorldReceiverHandler() = default;

#ifdef __cpp_impl_coroutine
virtual asio::awaitable<void> hello_world(std::string in) noexcept = 0;
virtual asio::awaitable<void> notice(int32_t in,
Expand All @@ -859,6 +884,9 @@ struct AsioCoroHelloWorldReceiverHandler {
};

struct FrpcCoroHelloWorldReceiverHandler {
FrpcCoroHelloWorldReceiverHandler() = default;
virtual ~FrpcCoroHelloWorldReceiverHandler() = default;

#ifdef __cpp_impl_coroutine
virtual frpc::Task<void> hello_world(std::string in) noexcept = 0;
virtual frpc::Task<void> notice(int32_t in, std::string info) noexcept = 0;
Expand Down Expand Up @@ -931,6 +959,11 @@ class HelloWorldReceiver final {
#endif
}

HelloWorldReceiver(const HelloWorldReceiver&) = delete;
HelloWorldReceiver& operator=(const HelloWorldReceiver&) = delete;
HelloWorldReceiver(HelloWorldReceiver&&) = delete;
HelloWorldReceiver& operator=(HelloWorldReceiver&&) = delete;

void start() {
m_channel->start();
}
Expand Down Expand Up @@ -1126,6 +1159,11 @@ class HelloWorldSender final {
~HelloWorldSender() {
}

HelloWorldSender(const HelloWorldSender&) = delete;
HelloWorldSender& operator=(const HelloWorldSender&) = delete;
HelloWorldSender(HelloWorldSender&&) = delete;
HelloWorldSender& operator=(HelloWorldSender&&) = delete;

static auto create(frpc::ChannelConfig& config) {
if ((config.socktype != zmq::socket_type::pub) &&
config.socktype != zmq::socket_type::push)
Expand Down Expand Up @@ -1291,6 +1329,11 @@ class StreamClient final {
m_pool_ptr->stop();
}

StreamClient(const StreamClient&) = delete;
StreamClient& operator=(const StreamClient&) = delete;
StreamClient(StreamClient&&) = delete;
StreamClient& operator=(StreamClient&&) = delete;

void start() {
m_channel->start();
}
Expand Down Expand Up @@ -1430,13 +1473,19 @@ class StreamClient final {
};

struct StreamServerHandler {
StreamServerHandler() = default;
virtual ~StreamServerHandler() = default;

virtual void hello_world(
std::shared_ptr<asio::experimental::concurrent_channel<
void(frpc::error_code, std::string)>>,
std::shared_ptr<frpc::Stream<void(std::string)>>) noexcept = 0;
};

struct CoroStreamServerHandler {
CoroStreamServerHandler() = default;
virtual ~CoroStreamServerHandler() = default;

#ifdef __cpp_impl_coroutine
virtual asio::awaitable<void> hello_world(
std::shared_ptr<asio::experimental::concurrent_channel<
Expand Down Expand Up @@ -1502,6 +1551,11 @@ class StreamServer final {
m_pool_ptr->stop();
}

StreamServer(const StreamServer&) = delete;
StreamServer& operator=(const StreamServer&) = delete;
StreamServer(StreamServer&&) = delete;
StreamServer& operator=(StreamServer&&) = delete;

decltype(auto) socket() {
return m_channel->socket();
}
Expand Down
11 changes: 9 additions & 2 deletions out/bi_web/include/impl/asio_context_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#ifndef _FRPC_CONTEXT_POOL_H_
#define _FRPC_CONTEXT_POOL_H_

#include <list>
#include <thread>

#ifdef FRPC_USE_BOOST_ASIO
#include <boost/asio.hpp>
#include <boost/asio/experimental/concurrent_channel.hpp>
Expand Down Expand Up @@ -38,12 +41,16 @@ class ContextPool final {

void start() {
for (auto& context : m_io_contexts)
m_threads.emplace_back(std::jthread([&] { context->run(); }));
m_threads.emplace_back(std::thread([&] { context->run(); }));
}

void stop() {
for (auto& context_ptr : m_io_contexts)
context_ptr->stop();
for (auto& thread : m_threads) {
if (thread.joinable())
thread.join();
}
}

asio::io_context& getIoContext() {
Expand All @@ -62,7 +69,7 @@ class ContextPool final {
std::vector<std::shared_ptr<asio::io_context>> m_io_contexts;
std::list<asio::any_io_executor> m_work;
std::atomic_uint64_t m_next_io_context;
std::vector<std::jthread> m_threads;
std::vector<std::thread> m_threads;
};

} // namespace frpc
Expand Down
5 changes: 1 addition & 4 deletions out/bi_web/include/impl/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
#define _FRPC_COROUTINE_H_

#include <algorithm>
#include <atomic>
#include <cassert>
#include <condition_variable>
#include <coroutine>
#include <exception>
#include <future>
#include <mutex>
#include <optional>
#include <type_traits>
#include <functional>

namespace frpc {

Expand Down
2 changes: 2 additions & 0 deletions out/bi_web/include/impl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <functional>

#include <msgpack.hpp>
#include <zmq.hpp>
#include <uuid/uuid.h>
#include <nlohmann/json.hpp>

namespace nlohmann {

Expand Down
Loading

0 comments on commit feb1953

Please sign in to comment.