From f13a10b30d221f6f4b4371a3e7019f712e7267cf Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 8 Jul 2019 05:22:39 +0700 Subject: [PATCH] update README and little style fixes --- README.md | 6 +++--- headers/curly.hpp/curly.hpp | 16 ++++++++++++---- sources/curly.hpp/curly.cpp | 17 +++++------------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 78c0568..0c84ad7 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ - Custom headers - Asynchronous requests - Different types of timeouts -- Custom completion callbacks -- PUT, GET, HEAD, POST methods +- Completion and progress callbacks - Custom uploading and downloading streams +- PUT, GET, HEAD, POST, PATCH, DELETE, OPTIONS methods ## Installation @@ -244,7 +244,7 @@ netex::promise download(std::string url) { reject(net::exception("network error")); return; } - net::response response = request.get(); + net::response response = request.take(); if ( response.is_http_error() ) { reject(net::exception("server error")); return; diff --git a/headers/curly.hpp/curly.hpp b/headers/curly.hpp/curly.hpp index 68a1cc6..2e8648e 100644 --- a/headers/curly.hpp/curly.hpp +++ b/headers/curly.hpp/curly.hpp @@ -289,25 +289,33 @@ namespace curly_hpp template < typename Callback > request_builder& callback(Callback&& f) { - static_assert(std::is_convertible_v); + static_assert( + std::is_convertible_v, + "custom callback type error"); return callback(callback_t(std::forward(f))); } template < typename Uploader, typename... Args > request_builder& uploader(Args&&... args) { - static_assert(std::is_base_of_v); + static_assert( + std::is_base_of_v, + "custom uploader type error"); return uploader(std::make_unique(std::forward(args)...)); } template < typename Downloader, typename... Args > request_builder& downloader(Args&&... args) { - static_assert(std::is_base_of_v); + static_assert( + std::is_base_of_v, + "custom downloader type error"); return downloader(std::make_unique(std::forward(args)...)); } template < typename Progressor, typename... Args > request_builder& progressor(Args&&... args) { - static_assert(std::is_base_of_v); + static_assert( + std::is_base_of_v, + "custom progressor type error"); return progressor(std::make_unique(std::forward(args)...)); } private: diff --git a/sources/curly.hpp/curly.cpp b/sources/curly.hpp/curly.cpp index 6b268cf..ab034a4 100644 --- a/sources/curly.hpp/curly.cpp +++ b/sources/curly.hpp/curly.cpp @@ -121,14 +121,12 @@ namespace cvar_.notify_all(); } - bool try_dequeue(T& v) noexcept( - std::is_nothrow_move_assignable_v) - { + bool try_dequeue(T& v) { std::lock_guard guard(mutex_); if ( queue_.empty() ) { return false; } - v = std::move(queue_.front()); + v = queue_.front(); queue_.pop(); return true; } @@ -154,7 +152,7 @@ namespace } template < typename Clock, typename Duration > - bool wait_until(const std::chrono::time_point& time) const { + bool wait_until(const std::chrono::time_point& time) const noexcept { std::unique_lock lock(mutex_); return cvar_.wait_until(lock, time, [this](){ return !queue_.empty(); @@ -171,9 +169,6 @@ namespace std::string header_builder; curl_slist* result = nullptr; for ( const auto& [key,value] : headers ) { - if ( key.empty() ) { - continue; - } try { header_builder.clear(); header_builder.append(key); @@ -214,14 +209,12 @@ namespace class curl_state final { public: template < typename F > - static std::invoke_result_t with(F&& f) - noexcept(std::is_nothrow_invocable_v) - { + static std::invoke_result_t with(F&& f) { std::lock_guard guard(mutex_); if ( !self_ ) { self_ = std::make_unique(); } - return std::forward(f)(self_->curlm_); + return std::invoke(std::forward(f), self_->curlm_); } public: curl_state() {