Skip to content

Commit

Permalink
Update .clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakuh committed Jun 6, 2022
1 parent 8652543 commit ecb9872
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 64 deletions.
19 changes: 18 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions curlio/detail/curl_share_lock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
33 changes: 9 additions & 24 deletions curlio/detail/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,40 @@ template<typename Type>
class Function;

template<typename Return, typename... Arguments>
class Invoker
{
class Invoker {
public:
virtual ~Invoker() = default;
virtual Return invoke(Arguments... arguments) = 0;
};

template<typename Functor, typename Return, typename... Arguments>
class Functor_invoker : public Invoker<Return, Arguments...>
{
class Functor_invoker : public Invoker<Return, Arguments...> {
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>(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>(arguments)...); }

private:
Functor _functor;
};

template<typename Return, typename... Arguments>
class Function<Return(Arguments...)>
{
class Function<Return(Arguments...)> {
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<typename Functor>
Function(Functor&& functor)
: _invoker{ std::make_unique<Functor_invoker<typename std::decay<Functor>::type, Return, Arguments...>>(
std::forward<Functor>(functor)) }
{}
void reset()
{
_invoker = nullptr;
}
void reset() { _invoker = nullptr; }
Return operator()(Arguments... arguments)
{
return _invoker->invoke(std::forward<Arguments>(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)
{
Expand Down
6 changes: 2 additions & 4 deletions curlio/detail/header_collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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<std::string, std::string, Insensitive_less> Fields;

Expand Down
8 changes: 3 additions & 5 deletions curlio/detail/shared_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 6 additions & 12 deletions curlio/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

namespace curlio {

enum class Code
{
enum class Code {
success,

multiple_reads,
Expand All @@ -19,8 +18,7 @@ enum class Code
no_response_code,
};

enum class Condition
{
enum class Condition {
success,
usage,
};
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -96,11 +92,9 @@ inline std::error_condition make_error_condition(Condition condition) noexcept
namespace std {

template<>
struct is_error_code_enum<curlio::Code> : true_type
{};
struct is_error_code_enum<curlio::Code> : true_type {};

template<>
struct is_error_condition_enum<curlio::Condition> : true_type
{};
struct is_error_condition_enum<curlio::Condition> : true_type {};

} // namespace std
6 changes: 3 additions & 3 deletions curlio/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

# define CURLIO_TRACE(stream) static_cast<void>(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<void>(0)
# define CURLIO_DEBUG(stream) static_cast<void>(0)
Expand Down
3 changes: 1 addition & 2 deletions curlio/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace curlio {

class Session;

class Request
{
class Request {
public:
typedef boost::asio::any_io_executor executor_type;

Expand Down
6 changes: 3 additions & 3 deletions curlio/response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace curlio {

class Session;

class Response
{
class Response {
public:
typedef boost::asio::any_io_executor executor_type;

Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions curlio/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

namespace curlio {

class Session
{
class Session {
public:
typedef boost::asio::any_io_executor executor_type;

Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -219,6 +217,7 @@ inline int Session::_multi_timer_callback(CURLM* multi, long timeout_ms, void* s
}
}
});
CURLIO_DEBUG("Exiting multi timer");

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/playground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit ecb9872

Please sign in to comment.