Compare commits
6 Commits
9fb1c747a6
...
6bb3351cb8
Author | SHA1 | Date | |
---|---|---|---|
6bb3351cb8 | |||
6086a0ea12 | |||
b4b688d3b9 | |||
43bf3c0cb2 | |||
26897c256b | |||
a788563db6 |
@ -69,21 +69,21 @@ private:
|
||||
|
||||
void put_client(std::shared_ptr<client> &cli);
|
||||
|
||||
[[nodiscard]] auto read_packet(client &cli, packet &response)
|
||||
-> packet::error_type;
|
||||
[[nodiscard]] auto read_packet(client &cli,
|
||||
packet &response) const -> packet::error_type;
|
||||
|
||||
void resolve();
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto send(std::string_view method, std::uint32_t &service_flags)
|
||||
-> packet::error_type;
|
||||
[[nodiscard]] auto send(std::string_view method,
|
||||
std::uint32_t &service_flags) -> packet::error_type;
|
||||
|
||||
[[nodiscard]] auto send(std::string_view method, packet &request,
|
||||
std::uint32_t &service_flags) -> packet::error_type;
|
||||
|
||||
[[nodiscard]] auto send(std::string_view method, packet &request,
|
||||
packet &response, std::uint32_t &service_flags)
|
||||
-> packet::error_type;
|
||||
packet &response,
|
||||
std::uint32_t &service_flags) -> packet::error_type;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_INCLUDE_UTILS_THROTTLE_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_THROTTLE_HPP_
|
||||
|
||||
namespace repertory {
|
||||
class throttle final {
|
||||
public:
|
||||
throttle() : max_size_(10u) {}
|
||||
|
||||
explicit throttle(std::size_t max_size) : max_size_(max_size) {}
|
||||
|
||||
public:
|
||||
throttle(const throttle &) noexcept = delete;
|
||||
throttle(throttle &&) noexcept = delete;
|
||||
auto operator=(const throttle &) -> throttle & = delete;
|
||||
auto operator=(throttle &&) -> throttle & = delete;
|
||||
|
||||
public:
|
||||
~throttle() { shutdown(); }
|
||||
|
||||
private:
|
||||
const std::size_t max_size_;
|
||||
std::size_t count_ = 0u;
|
||||
bool shutdown_ = false;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable notify_;
|
||||
|
||||
public:
|
||||
void decrement();
|
||||
|
||||
void increment_or_wait();
|
||||
|
||||
void reset();
|
||||
|
||||
void shutdown();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_THROTTLE_HPP_
|
@ -146,18 +146,20 @@ void client_pool::remove_client(const std::string &client_id) {
|
||||
}
|
||||
|
||||
void client_pool::shutdown() {
|
||||
if (not shutdown_) {
|
||||
event_system::instance().raise<service_shutdown_begin>("client_pool");
|
||||
unique_mutex_lock pool_lock(pool_mutex_);
|
||||
if (not shutdown_) {
|
||||
shutdown_ = true;
|
||||
for (auto &pool_entry : pool_lookup_) {
|
||||
pool_entry.second->shutdown();
|
||||
}
|
||||
pool_lookup_.clear();
|
||||
}
|
||||
pool_lock.unlock();
|
||||
event_system::instance().raise<service_shutdown_end>("client_pool");
|
||||
if (shutdown_) {
|
||||
return;
|
||||
}
|
||||
|
||||
event_system::instance().raise<service_shutdown_begin>("client_pool");
|
||||
unique_mutex_lock pool_lock(pool_mutex_);
|
||||
if (not shutdown_) {
|
||||
shutdown_ = true;
|
||||
for (auto &pool_entry : pool_lookup_) {
|
||||
pool_entry.second->shutdown();
|
||||
}
|
||||
pool_lookup_.clear();
|
||||
}
|
||||
pool_lock.unlock();
|
||||
event_system::instance().raise<service_shutdown_end>("client_pool");
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@ -49,8 +49,10 @@ packet_client::~packet_client() {
|
||||
|
||||
void packet_client::close(client &cli) {
|
||||
try {
|
||||
cli.socket.shutdown(boost::asio::socket_base::shutdown_both);
|
||||
|
||||
boost::system::error_code err;
|
||||
cli.socket.close(err);
|
||||
[[maybe_unused]] auto res = cli.socket.close(err);
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
@ -110,15 +112,15 @@ void packet_client::put_client(std::shared_ptr<client> &cli) {
|
||||
}
|
||||
}
|
||||
|
||||
auto packet_client::read_packet(client &cli, packet &response)
|
||||
-> packet::error_type {
|
||||
auto packet_client::read_packet(client &cli,
|
||||
packet &response) const -> packet::error_type {
|
||||
data_buffer buffer(sizeof(std::uint32_t));
|
||||
const auto read_buffer = [&]() {
|
||||
std::uint32_t offset{};
|
||||
while (offset < buffer.size()) {
|
||||
auto bytes_read = boost::asio::read(
|
||||
cli.socket,
|
||||
boost::asio::buffer(&buffer[offset], buffer.size() - offset));
|
||||
boost::asio::buffer(&buffer.at(offset), buffer.size() - offset));
|
||||
if (bytes_read <= 0) {
|
||||
throw std::runtime_error("read failed|" + std::to_string(bytes_read));
|
||||
}
|
||||
@ -152,8 +154,8 @@ void packet_client::resolve() {
|
||||
.resolve(cfg_.host_name_or_ip, std::to_string(cfg_.api_port));
|
||||
}
|
||||
|
||||
auto packet_client::send(std::string_view method, std::uint32_t &service_flags)
|
||||
-> packet::error_type {
|
||||
auto packet_client::send(std::string_view method,
|
||||
std::uint32_t &service_flags) -> packet::error_type {
|
||||
packet request;
|
||||
return send(method, request, service_flags);
|
||||
}
|
||||
@ -165,8 +167,8 @@ auto packet_client::send(std::string_view method, packet &request,
|
||||
}
|
||||
|
||||
auto packet_client::send(std::string_view method, packet &request,
|
||||
packet &response, std::uint32_t &service_flags)
|
||||
-> packet::error_type {
|
||||
packet &response,
|
||||
std::uint32_t &service_flags) -> packet::error_type {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto success = false;
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "utils/throttle.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
void throttle::decrement() {
|
||||
mutex_lock l(mutex_);
|
||||
if (not shutdown_) {
|
||||
if (count_ > 0) {
|
||||
count_--;
|
||||
}
|
||||
notify_.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
void throttle::increment_or_wait() {
|
||||
unique_mutex_lock l(mutex_);
|
||||
if (not shutdown_) {
|
||||
if (count_ >= max_size_) {
|
||||
notify_.wait(l);
|
||||
}
|
||||
if (not shutdown_) {
|
||||
count_++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void throttle::reset() {
|
||||
unique_mutex_lock l(mutex_);
|
||||
if (shutdown_) {
|
||||
count_ = 0;
|
||||
shutdown_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void throttle::shutdown() {
|
||||
if (not shutdown_) {
|
||||
unique_mutex_lock l(mutex_);
|
||||
shutdown_ = true;
|
||||
notify_.notify_all();
|
||||
}
|
||||
}
|
||||
} // namespace repertory
|
@ -35,7 +35,7 @@ fi
|
||||
|
||||
pushd "${PROJECT_SOURCE_DIR}"
|
||||
BRANCH=$(git branch --show-current)
|
||||
RELEASE=$(grep set\(PROJECT_RELEASE_ITER ./config.sh | sed s/\)//g | awk '{print $2}')
|
||||
RELEASE=$(grep PROJECT_RELEASE_ITER= ./config.sh | sed s/PROJECT_RELEASE_ITER=//g)
|
||||
popd
|
||||
|
||||
if [ "${BRANCH}" == "master" ] || [ "${BRANCH}" == "alpha" ] || [ "${BRANCH}" == "beta" ] || [ "${BRANCH}" == "rc" ]; then
|
||||
|
Reference in New Issue
Block a user