diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 4c3abfe43..b6875aae0 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -18,7 +18,7 @@ jobs: with: fetch-depth: 0 - name: install clang-format - run: sudo apt install clang-format + run: pip install clang-format - name: check-diff run: | diff=`git-clang-format --diff HEAD^` diff --git a/include/ylt/coro_io/io_context_pool.hpp b/include/ylt/coro_io/io_context_pool.hpp index fa406b318..fb951e223 100644 --- a/include/ylt/coro_io/io_context_pool.hpp +++ b/include/ylt/coro_io/io_context_pool.hpp @@ -331,7 +331,7 @@ class multithread_context_pool { ~multithread_context_pool() { stop(); } void run() { - for (int i = 0; i < thd_num_; i++) { + for (size_t i = 0; i < thd_num_; i++) { thds_.emplace_back([this] { ioc_.run(); }); diff --git a/include/ylt/coro_rpc/impl/coro_rpc_client.hpp b/include/ylt/coro_rpc/impl/coro_rpc_client.hpp index 5dc651aae..44d75fa5c 100644 --- a/include/ylt/coro_rpc/impl/coro_rpc_client.hpp +++ b/include/ylt/coro_rpc/impl/coro_rpc_client.hpp @@ -139,10 +139,10 @@ struct async_rpc_result_value_t : public detail::async_rpc_result_base { T result_; public: - async_rpc_result_value_t(T &&result, resp_body &&buffer, + async_rpc_result_value_t(T&& result, resp_body&& buffer, coro_io::data_view attachment) - : result_(std::move(result)), - async_rpc_result_base(std::move(buffer), attachment) {} + : async_rpc_result_base(std::move(buffer), attachment), + result_(std::move(result)) {} async_rpc_result_value_t(T &&result) : result_(std::move(result)) {} T &result() noexcept { return result_; } const T &result() const noexcept { return result_; } @@ -268,11 +268,11 @@ class coro_rpc_client { * @param executor coro_io's executor, default executor is come */ coro_rpc_client( - coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor(), + coro_io::ExecutorWrapper<>* executor = coro_io::get_global_executor(), config conf = {}) - : control_(std::make_shared(executor, false, conf.local_ip)), - timer_(std::make_unique( - executor->get_asio_executor())) { + : timer_(std::make_unique( + executor->get_asio_executor())), + control_(std::make_shared(executor, false, conf.local_ip)) { if (!init_config(conf)) [[unlikely]] { close(); } @@ -1388,10 +1388,8 @@ class coro_rpc_client { private: template async_simple::coro::Lazy send_request_for_impl( - Socket &soc, request_config_t &config, uint32_t &id, - coro_io::period_timer &timer, Args &&...args) { - using R = decltype(get_return_type()); - + Socket& soc, request_config_t& config, uint32_t& id, + coro_io::period_timer& timer, Args&&... args) { if (control_->has_closed_) AS_UNLIKELY { ELOG_ERROR << "client has been closed, please re-connect" @@ -1438,7 +1436,7 @@ class coro_rpc_client { char buffer[coro_rpc_protocol::RESP_HEAD_LEN]; auto tp = std::chrono::steady_clock::now(); ret = co_await coro_io::async_read(socket, asio::buffer(buffer)); - auto ec = struct_pack::deserialize_to< + [[maybe_unused]] auto ec = struct_pack::deserialize_to< struct_pack::sp_config::DISABLE_ALL_META_INFO>( header, std::string_view{buffer, buffer + sizeof(buffer)}); assert(!ec); diff --git a/include/ylt/coro_rpc/impl/coro_rpc_server.hpp b/include/ylt/coro_rpc/impl/coro_rpc_server.hpp index 8e20fde80..2733fe8f8 100644 --- a/include/ylt/coro_rpc/impl/coro_rpc_server.hpp +++ b/include/ylt/coro_rpc/impl/coro_rpc_server.hpp @@ -87,9 +87,9 @@ class coro_rpc_server_base { conn_timeout_duration = std::chrono::seconds(0), bool is_enable_tcp_no_delay = true) : pool_(thread_num), - conn_timeout_duration_(conn_timeout_duration), flag_{stat::init}, - is_enable_tcp_no_delay_(is_enable_tcp_no_delay) { + is_enable_tcp_no_delay_(is_enable_tcp_no_delay), + conn_timeout_duration_(conn_timeout_duration) { acceptors_.push_back( std::make_unique(address, port)); } @@ -99,21 +99,21 @@ class coro_rpc_server_base { conn_timeout_duration = std::chrono::seconds(0), bool is_enable_tcp_no_delay = true) : pool_(thread_num), - conn_timeout_duration_(conn_timeout_duration), flag_{stat::init}, - is_enable_tcp_no_delay_(is_enable_tcp_no_delay) { + is_enable_tcp_no_delay_(is_enable_tcp_no_delay), + conn_timeout_duration_(conn_timeout_duration) { acceptors_.push_back( std::make_unique(address)); } coro_rpc_server_base( - const server_config &config, + const server_config& config, std::vector> acceptors = {}) : pool_(config.thread_num), - conn_timeout_duration_(config.conn_timeout_duration), flag_{stat::init}, - is_enable_tcp_no_delay_(config.is_enable_tcp_no_delay) { + is_enable_tcp_no_delay_(config.is_enable_tcp_no_delay), + conn_timeout_duration_(config.conn_timeout_duration) { #ifdef YLT_ENABLE_SSL if (config.ssl_config) { use_ssl_ = init_ssl_context_helper(context_, config.ssl_config.value()); diff --git a/include/ylt/coro_rpc/impl/protocol/coro_rpc_protocol.hpp b/include/ylt/coro_rpc/impl/protocol/coro_rpc_protocol.hpp index 6b8584506..f566d5f01 100644 --- a/include/ylt/coro_rpc/impl/protocol/coro_rpc_protocol.hpp +++ b/include/ylt/coro_rpc/impl/protocol/coro_rpc_protocol.hpp @@ -105,8 +105,6 @@ struct coro_rpc_protocol { if (ec) [[unlikely]] { co_return std::move(ec); } - auto i = struct_pack::get_needed_size< - struct_pack::sp_config::DISABLE_ALL_META_INFO>(req_head); auto ec2 = struct_pack::deserialize_to< struct_pack::sp_config::DISABLE_ALL_META_INFO>( req_head, @@ -179,8 +177,6 @@ struct coro_rpc_protocol { if (ec) [[unlikely]] { co_return std::move(ec); } - auto i = struct_pack::get_needed_size< - struct_pack::sp_config::DISABLE_ALL_META_INFO>(req_head); auto ec2 = struct_pack::deserialize_to< struct_pack::sp_config::DISABLE_ALL_META_INFO>( req_head, diff --git a/include/ylt/easylog/appender.hpp b/include/ylt/easylog/appender.hpp index e263725b1..359949366 100644 --- a/include/ylt/easylog/appender.hpp +++ b/include/ylt/easylog/appender.hpp @@ -38,7 +38,7 @@ constexpr char digits[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; template inline void to_int(int num, char *p, int &size) { - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { p[--size] = digits[num % 10]; num = num / 10; } @@ -94,11 +94,11 @@ inline char *get_time_str(const auto &now) { class appender { public: appender() = default; - appender(const std::string &filename, bool async, bool enable_console, + appender(const std::string& filename, bool async, bool enable_console, size_t max_file_size, size_t max_files, bool flush_every_time) : has_init_(true), - flush_every_time_(flush_every_time), enable_console_(enable_console), + flush_every_time_(flush_every_time), max_file_size_(max_file_size) { filename_ = filename; max_files_ = (std::min)(max_files, static_cast(1000)); diff --git a/include/ylt/standalone/cinatra/coro_http_request.hpp b/include/ylt/standalone/cinatra/coro_http_request.hpp index 2a3edebb6..bc187930f 100644 --- a/include/ylt/standalone/cinatra/coro_http_request.hpp +++ b/include/ylt/standalone/cinatra/coro_http_request.hpp @@ -73,13 +73,13 @@ inline std::vector> parse_ranges(std::string_view range_str, } } - if (start > 0 && (start >= file_size || start == end)) { + if (start > 0 && (start >= static_cast(file_size) || start == end)) { // out of range is_valid = false; return {}; } - if (end > 0 && end >= file_size) { + if (end > 0 && end >= static_cast(file_size)) { end = file_size - 1; } diff --git a/include/ylt/standalone/cinatra/coro_http_server.hpp b/include/ylt/standalone/cinatra/coro_http_server.hpp index 0d59fcd41..daed2c3f2 100644 --- a/include/ylt/standalone/cinatra/coro_http_server.hpp +++ b/include/ylt/standalone/cinatra/coro_http_server.hpp @@ -609,7 +609,7 @@ class coro_http_server { co_return; } - for (int i = 0; i < ranges.size(); i++) { + for (size_t i = 0; i < ranges.size(); i++) { std::string &part_header = multi_heads[i]; r = co_await req.get_conn()->write_data(part_header); if (!r) { @@ -1109,7 +1109,6 @@ class coro_http_server { asio::ip::address_v6::bytes_type bytes; unsigned long scope_id = 0; - struct in6_addr addr; asio::error_code ec; return asio::detail::socket_ops::inet_pton(ASIO_OS_DEF(AF_INET6), address.data(), &bytes[0], diff --git a/include/ylt/standalone/cinatra/coro_radix_tree.hpp b/include/ylt/standalone/cinatra/coro_radix_tree.hpp index 1fffeea26..14c820a87 100644 --- a/include/ylt/standalone/cinatra/coro_radix_tree.hpp +++ b/include/ylt/standalone/cinatra/coro_radix_tree.hpp @@ -393,7 +393,7 @@ class radix_tree { private: int find_pos(const std::string &str, char target, int start) { auto i = str.find(target, start); - return i == -1 ? str.size() : i; + return i == std::string::npos ? str.size() : i; } std::shared_ptr root; diff --git a/include/ylt/standalone/cinatra/session.hpp b/include/ylt/standalone/cinatra/session.hpp index 3b3fcbdf6..248cfc962 100644 --- a/include/ylt/standalone/cinatra/session.hpp +++ b/include/ylt/standalone/cinatra/session.hpp @@ -69,7 +69,7 @@ class session { return session_id_; } - std::size_t get_time_stamp() { + std::time_t get_time_stamp() { std::unique_lock lock(mtx_); return time_stamp_; } diff --git a/include/ylt/standalone/cinatra/time_util.hpp b/include/ylt/standalone/cinatra/time_util.hpp index a0eb3345e..0c5e76a1e 100644 --- a/include/ylt/standalone/cinatra/time_util.hpp +++ b/include/ylt/standalone/cinatra/time_util.hpp @@ -263,7 +263,7 @@ constexpr std::string_view YMON[12] = {"Jan", "Feb", "Mar", "Apr", template inline void to_int(int num, char c, char *p) { - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { p[N - 1 - i] = digits[num % 10]; num = num / 10; } @@ -301,7 +301,7 @@ inline std::string_view get_local_time_str(char (&buf)[N], std::time_t t, char *p = buf; - for (int i = 0; i < format.size(); ++i) { + for (size_t i = 0; i < format.size(); ++i) { if (format[i] == '%') { char c = i + 2 < format.size() ? format[i + 2] : '0'; i++; diff --git a/include/ylt/standalone/cinatra/websocket.hpp b/include/ylt/standalone/cinatra/websocket.hpp index 953853e15..7a507e5a1 100644 --- a/include/ylt/standalone/cinatra/websocket.hpp +++ b/include/ylt/standalone/cinatra/websocket.hpp @@ -184,7 +184,7 @@ class websocket { } void encode_ws_payload(std::span &data) { - for (int i = 0; i < data.size(); ++i) { + for (size_t i = 0; i < data.size(); ++i) { data[i] ^= mask_key_[i % 4]; } } diff --git a/include/ylt/struct_pack/md5_constexpr.hpp b/include/ylt/struct_pack/md5_constexpr.hpp index bc21e4988..14c001329 100644 --- a/include/ylt/struct_pack/md5_constexpr.hpp +++ b/include/ylt/struct_pack/md5_constexpr.hpp @@ -43,7 +43,7 @@ struct string_literal { constexpr bool operator!=( const string_literal &other) const { if constexpr (Size == Size2) { - for (int i = 0; i < Size; ++i) { + for (size_t i = 0; i < Size; ++i) { if ((*this)[i] != other[i]) return true; } diff --git a/include/ylt/util/time_util.h b/include/ylt/util/time_util.h index f9645103b..468238b4f 100644 --- a/include/ylt/util/time_util.h +++ b/include/ylt/util/time_util.h @@ -410,7 +410,7 @@ constexpr std::string_view YMON[12] = {"Jan", "Feb", "Mar", "Apr", template inline void to_int(int num, char c, char *p) { - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { p[N - 1 - i] = digits[num % 10]; num = num / 10; } @@ -448,7 +448,7 @@ inline std::string_view get_local_time_str(char (&buf)[N], std::time_t t, char *p = buf; - for (int i = 0; i < format.size(); ++i) { + for (size_t i = 0; i < format.size(); ++i) { if (format[i] == '%') { char c = i + 2 < format.size() ? format[i + 2] : '0'; i++;