From ecb9872095800b644de7398b0543c942749804ea Mon Sep 17 00:00:00 2001 From: terrakuh Date: Mon, 6 Jun 2022 22:27:35 +0200 Subject: [PATCH] Update .clang-format --- .clang-format | 19 ++++++++++++++++- curlio/detail/curl_share_lock.hpp | 3 +-- curlio/detail/function.hpp | 33 ++++++++---------------------- curlio/detail/header_collector.hpp | 6 ++---- curlio/detail/shared_data.hpp | 8 +++----- curlio/error.hpp | 18 ++++++---------- curlio/log.hpp | 6 +++--- curlio/request.hpp | 3 +-- curlio/response.hpp | 6 +++--- curlio/session.hpp | 13 ++++++------ examples/playground.cpp | 2 +- 11 files changed, 53 insertions(+), 64 deletions(-) diff --git a/.clang-format b/.clang-format index fa809c0..4b3ec86 100644 --- a/.clang-format +++ b/.clang-format @@ -14,11 +14,28 @@ AllowShortLoopsOnASingleLine: 'true' AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: 'false' AlwaysBreakTemplateDeclarations: 'Yes' +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false BinPackArguments: 'true' BinPackParameters: 'true' BreakAfterJavaFieldAnnotations: 'true' BreakBeforeBinaryOperators: None -BreakBeforeBraces: Mozilla +BreakBeforeBraces: Custom BreakBeforeTernaryOperators: 'true' BreakConstructorInitializers: BeforeColon BreakInheritanceList: BeforeColon diff --git a/curlio/detail/curl_share_lock.hpp b/curlio/detail/curl_share_lock.hpp index f5f94db..439f06e 100644 --- a/curlio/detail/curl_share_lock.hpp +++ b/curlio/detail/curl_share_lock.hpp @@ -6,8 +6,7 @@ namespace curlio::detail { -class CURL_share_lock -{ +class CURL_share_lock { public: void lock(CURL* handle, curl_lock_data data, curl_lock_access access, void* self_pointer) noexcept { diff --git a/curlio/detail/function.hpp b/curlio/detail/function.hpp index 824da26..0c35abb 100644 --- a/curlio/detail/function.hpp +++ b/curlio/detail/function.hpp @@ -10,55 +10,40 @@ template class Function; template -class Invoker -{ +class Invoker { public: virtual ~Invoker() = default; virtual Return invoke(Arguments... arguments) = 0; }; template -class Functor_invoker : public Invoker -{ +class Functor_invoker : public Invoker { public: - Functor_invoker(const Functor& functor) : _functor{ functor } - {} - Functor_invoker(Functor&& functor) : _functor{ std::move(functor) } - {} - Return invoke(Arguments... arguments) override - { - return _functor(std::forward(arguments)...); - } + Functor_invoker(const Functor& functor) : _functor{ functor } {} + Functor_invoker(Functor&& functor) : _functor{ std::move(functor) } {} + Return invoke(Arguments... arguments) override { return _functor(std::forward(arguments)...); } private: Functor _functor; }; template -class Function -{ +class Function { public: Function() = default; Function(const Function& copy) = delete; - Function(Function&& move) : _invoker{ std::move(move._invoker) } - {} + Function(Function&& move) : _invoker{ std::move(move._invoker) } {} template Function(Functor&& functor) : _invoker{ std::make_unique::type, Return, Arguments...>>( std::forward(functor)) } {} - void reset() - { - _invoker = nullptr; - } + void reset() { _invoker = nullptr; } Return operator()(Arguments... arguments) { return _invoker->invoke(std::forward(arguments)...); } - operator bool() const noexcept - { - return _invoker != nullptr; - } + operator bool() const noexcept { return _invoker != nullptr; } Function& operator=(const Function& copy) = delete; Function& operator =(Function&& move) { diff --git a/curlio/detail/header_collector.hpp b/curlio/detail/header_collector.hpp index 0c3268c..96cf306 100644 --- a/curlio/detail/header_collector.hpp +++ b/curlio/detail/header_collector.hpp @@ -13,8 +13,7 @@ namespace curlio::detail { -struct Insensitive_less -{ +struct Insensitive_less { bool operator()(const std::string& lhs, const std::string& rhs) const noexcept { if (lhs.size() < rhs.size()) { @@ -37,8 +36,7 @@ struct Insensitive_less /// Hooks into the header callbacks of cURL and parses the header fields. Hook management must be done /// separately. -class Header_collector -{ +class Header_collector { public: typedef std::map Fields; diff --git a/curlio/detail/shared_data.hpp b/curlio/detail/shared_data.hpp index c6cab4f..63326d1 100644 --- a/curlio/detail/shared_data.hpp +++ b/curlio/detail/shared_data.hpp @@ -7,15 +7,13 @@ namespace curlio::detail { -enum Status -{ - finished = 0x1, +enum Status { + finished = 0x1, // headers_finished = 0x2, }; /// Contains data shared between Request and Response. -class Shared_data -{ +class Shared_data { public: boost::asio::any_io_executor executor; CURL* const handle = curl_easy_init(); diff --git a/curlio/error.hpp b/curlio/error.hpp index a837e99..7a2e89e 100644 --- a/curlio/error.hpp +++ b/curlio/error.hpp @@ -5,8 +5,7 @@ namespace curlio { -enum class Code -{ +enum class Code { success, multiple_reads, @@ -19,8 +18,7 @@ enum class Code no_response_code, }; -enum class Condition -{ +enum class Condition { success, usage, }; @@ -29,8 +27,7 @@ std::error_condition make_error_condition(Condition condition) noexcept; inline const std::error_category& code_category() noexcept { - static class : public std::error_category - { + static class : public std::error_category { public: const char* name() const noexcept override { return "curlio"; } std::error_condition default_error_condition(int code) const noexcept override @@ -65,8 +62,7 @@ inline const std::error_category& code_category() noexcept inline const std::error_category& condition_category() noexcept { - static class : public std::error_category - { + static class : public std::error_category { public: const char* name() const noexcept override { return "curlio"; } std::string message(int condition) const override @@ -96,11 +92,9 @@ inline std::error_condition make_error_condition(Condition condition) noexcept namespace std { template<> -struct is_error_code_enum : true_type -{}; +struct is_error_code_enum : true_type {}; template<> -struct is_error_condition_enum : true_type -{}; +struct is_error_condition_enum : true_type {}; } // namespace std diff --git a/curlio/log.hpp b/curlio/log.hpp index 72f3eab..66d1a0d 100644 --- a/curlio/log.hpp +++ b/curlio/log.hpp @@ -6,9 +6,9 @@ # define CURLIO_TRACE(stream) static_cast(0) // # define CURLIO_TRACE(stream) std::cout << "TRACE: " << stream << "\n" -# define CURLIO_DEBUG(stream) std::cout << "DEBUG " << std::this_thread::get_id() << ":" << stream << "\n" -# define CURLIO_INFO(stream) std::cout << "INFO " << std::this_thread::get_id() << ":" << stream << "\n" -# define CURLIO_ERROR(stream) std::cout << "ERROR " << std::this_thread::get_id() << ":" << stream << "\n" +# define CURLIO_DEBUG(stream) std::cout << "DEBUG " << std::this_thread::get_id() << ": " << stream << "\n" +# define CURLIO_INFO(stream) std::cout << "INFO " << std::this_thread::get_id() << ": " << stream << "\n" +# define CURLIO_ERROR(stream) std::cout << "ERROR " << std::this_thread::get_id() << ": " << stream << "\n" #else # define CURLIO_TRACE(stream) static_cast(0) # define CURLIO_DEBUG(stream) static_cast(0) diff --git a/curlio/request.hpp b/curlio/request.hpp index 54600db..a353bb8 100644 --- a/curlio/request.hpp +++ b/curlio/request.hpp @@ -22,8 +22,7 @@ namespace curlio { class Session; -class Request -{ +class Request { public: typedef boost::asio::any_io_executor executor_type; diff --git a/curlio/response.hpp b/curlio/response.hpp index 7e0f09c..edd6a1f 100644 --- a/curlio/response.hpp +++ b/curlio/response.hpp @@ -20,8 +20,7 @@ namespace curlio { class Session; -class Response -{ +class Response { public: typedef boost::asio::any_io_executor executor_type; @@ -170,7 +169,8 @@ inline auto Response::async_read_some(const Mutable_buffer_sequence& buffers, To boost::asio::post(executor, std::bind(std::move(handler), boost::asio::error::eof, 0)); } else { // set write handler when cURL calls the write callback - _receive_handler = [this, buffers, executor=ptr->executor, + // TODO figure out why it works with this executor for large downloads with multiple threads + _receive_handler = [this, buffers, executor = ptr->executor, handler = std::move(handler)](boost::system::error_code ec) mutable { std::size_t copied = 0; // copy data and finish diff --git a/curlio/session.hpp b/curlio/session.hpp index 426e315..8defb4e 100644 --- a/curlio/session.hpp +++ b/curlio/session.hpp @@ -14,8 +14,7 @@ namespace curlio { -class Session -{ +class Session { public: typedef boost::asio::any_io_executor executor_type; @@ -31,8 +30,7 @@ class Session Session& operator=(Session&& move) = delete; private: - struct Socket_info - { + struct Socket_info { boost::asio::ip::tcp::socket socket; bool watch_read = false; bool watch_write = false; @@ -145,10 +143,10 @@ inline void Session::_async_wait(boost::asio::ip::tcp::socket& socket, socket.async_wait(type, [this, type, handle](boost::system::error_code ec) { CURLIO_TRACE("Socket action=" << (type == boost::asio::socket_base::wait_read ? "READ" : "WRITE") << " ec=" << ec.what()); - int still_running = 0; - const int mask = (type == boost::asio::socket_base::wait_read ? CURL_CSELECT_IN : CURL_CSELECT_OUT) | + const int mask = (type == boost::asio::socket_base::wait_read ? CURL_CSELECT_IN : CURL_CSELECT_OUT) | (ec ? CURL_CSELECT_ERR : 0); - const auto code = curl_multi_socket_action(_multi_handle, handle, mask, &still_running); + int still_running = 0; + const auto code = curl_multi_socket_action(_multi_handle, handle, mask, &still_running); if (code != CURLM_OK) { CURLIO_ERROR("Socket action: " << curl_multi_strerror(code)); } @@ -219,6 +217,7 @@ inline int Session::_multi_timer_callback(CURLM* multi, long timeout_ms, void* s } } }); + CURLIO_DEBUG("Exiting multi timer"); return 0; } diff --git a/examples/playground.cpp b/examples/playground.cpp index f7d34e7..a2ceeda 100644 --- a/examples/playground.cpp +++ b/examples/playground.cpp @@ -46,7 +46,7 @@ int main(int argc, char** argv) do { co_await resp.async_await_headers(use_awaitable); - std::cout << "=======RECEIVED HEADER======\n"; + std::cout << "=======RECEIVED HEADER======\n"; } while (resp.is_redirect()); std::cout << "Final headers received\n";