Skip to content

Commit

Permalink
Add setsockopt callback
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasy-peak committed Jul 24, 2024
1 parent f8e378f commit 2cb1c6c
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions out/bi_web/include/impl/bi_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class BiChannel final {
if (config.probe) {
m_socket_ptr->set(zmq::sockopt::probe_router, 1);
}
if (config.setsockopt_callback)
config.setsockopt_callback(*m_socket_ptr);
if (config.bind) {
if (config.socktype == zmq::socket_type::router) {
if (config.mandatory)
Expand Down
2 changes: 2 additions & 0 deletions out/bi_web/include/impl/uni_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class UniChannel final {
}
if (config.socktype == zmq::socket_type::sub)
m_socket_ptr->set(zmq::sockopt::subscribe, "");
if (config.setsockopt_callback)
config.setsockopt_callback(*m_socket_ptr);
if (config.bind)
m_socket_ptr->bind(config.addr);
else
Expand Down
1 change: 1 addition & 0 deletions out/bi_web/include/impl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct ChannelConfig {
std::size_t channel_size{50000};
std::optional<int32_t> heartbeat_timeout;
std::optional<int32_t> heartbeat_ivl;
std::function<void(zmq::socket_t&)> setsockopt_callback;
};

inline std::string createUuid() {
Expand Down
2 changes: 2 additions & 0 deletions out/include/impl/bi_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class BiChannel final {
if (config.probe) {
m_socket_ptr->set(zmq::sockopt::probe_router, 1);
}
if (config.setsockopt_callback)
config.setsockopt_callback(*m_socket_ptr);
if (config.bind) {
if (config.socktype == zmq::socket_type::router) {
if (config.mandatory)
Expand Down
2 changes: 2 additions & 0 deletions out/include/impl/uni_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class UniChannel final {
}
if (config.socktype == zmq::socket_type::sub)
m_socket_ptr->set(zmq::sockopt::subscribe, "");
if (config.setsockopt_callback)
config.setsockopt_callback(*m_socket_ptr);
if (config.bind)
m_socket_ptr->bind(config.addr);
else
Expand Down
1 change: 1 addition & 0 deletions out/include/impl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct ChannelConfig {
std::size_t channel_size{50000};
std::optional<int32_t> heartbeat_timeout;
std::optional<int32_t> heartbeat_ivl;
std::function<void(zmq::socket_t&)> setsockopt_callback;
};

inline std::string createUuid() {
Expand Down
2 changes: 2 additions & 0 deletions template/cpp/impl/bi_channel.inja
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ private:
if (config.probe) {
m_socket_ptr->set(zmq::sockopt::probe_router, 1);
}
if (config.setsockopt_callback)
config.setsockopt_callback(*m_socket_ptr);
if (config.bind) {
if (config.socktype == zmq::socket_type::router) {
if (config.mandatory)
Expand Down
2 changes: 2 additions & 0 deletions template/cpp/impl/uni_channel.inja
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ private:
}
if (config.socktype == zmq::socket_type::sub)
m_socket_ptr->set(zmq::sockopt::subscribe, "");
if (config.setsockopt_callback)
config.setsockopt_callback(*m_socket_ptr);
if (config.bind)
m_socket_ptr->bind(config.addr);
else
Expand Down
1 change: 1 addition & 0 deletions template/cpp/impl/utils.inja
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct ChannelConfig {
std::size_t channel_size{50000};
std::optional<int32_t> heartbeat_timeout;
std::optional<int32_t> heartbeat_ivl;
std::function<void(zmq::socket_t&)> setsockopt_callback;
};

inline std::string createUuid() {
Expand Down
4 changes: 4 additions & 0 deletions test/cpp/coro_bi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ asio::awaitable<void> start_client() {
void start_server() {
frpc::ChannelConfig bi_config{};
bi_config.addr = addr;
bi_config.setsockopt_callback = [](auto& socket) {
spdlog::info("setsockopt_callback");
socket.set(zmq::sockopt::heartbeat_ivl, 5000);
};
auto server = fantasy::HelloWorldServer::create(
bi_config,
std::make_shared<CoroHandler>(),
Expand Down

0 comments on commit 2cb1c6c

Please sign in to comment.