Skip to content

Commit

Permalink
Committing clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenberry committed Sep 16, 2024
1 parent b863ef9 commit ee01821
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
45 changes: 22 additions & 23 deletions include/glaze/ext/glaze_asio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,30 @@ namespace glz

template <class T>
using std_func_sig_t = typename func_traits<T>::std_func_sig;

struct socket_pool
{
std::string host{"localhost"}; // host name
std::string service{""}; // often the port
std::mutex mtx{};
std::vector<std::shared_ptr<asio::ip::tcp::socket>> sockets{2};
std::vector<size_t> available{0, 1}; // indices of available sockets

std::shared_ptr<asio::io_context> ctx{};
std::shared_ptr<std::atomic<bool>> is_connected = std::make_shared<std::atomic<bool>>(false);

// provides a pointer to a socket and an index
std::tuple<std::shared_ptr<asio::ip::tcp::socket>, size_t, std::error_code> get()
{
std::unique_lock lock{mtx};

// reset all socket pointers if a connection failed
if (not *is_connected) {
for (auto& socket : sockets) {
socket.reset();
}
}

if (available.empty()) {
const auto current_size = sockets.size();
const auto new_size = sockets.size() * 2;
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace glz
available.emplace_back(index);
}
};

struct unique_socket
{
socket_pool* pool{};
Expand All @@ -169,9 +169,9 @@ namespace glz
std::shared_ptr<asio::ip::tcp::socket> value() { return ptr; }

const std::shared_ptr<asio::ip::tcp::socket> value() const { return ptr; }

asio::ip::tcp::socket& operator*() { return *ptr; }

const asio::ip::tcp::socket& operator*() const { return *ptr; }

unique_socket(socket_pool* input_pool) : pool(input_pool) { std::tie(ptr, index, ec) = pool->get(); }
Expand Down Expand Up @@ -200,11 +200,10 @@ namespace glz
std::shared_ptr<glz::socket_pool> socket_pool = std::make_shared<glz::socket_pool>();

std::shared_ptr<repe::buffer_pool> buffer_pool = std::make_shared<repe::buffer_pool>();
std::shared_ptr<std::atomic<bool>> is_connected = std::make_shared<std::atomic<bool>>(false); // will be set to pool's boolean

bool connected() const {
return *is_connected;
}
std::shared_ptr<std::atomic<bool>> is_connected =
std::make_shared<std::atomic<bool>>(false); // will be set to pool's boolean

bool connected() const { return *is_connected; }

[[nodiscard]] std::error_code init()
{
Expand All @@ -213,7 +212,7 @@ namespace glz
socket_pool->host = host;
socket_pool->service = service;
is_connected = socket_pool->is_connected;

unique_socket socket{socket_pool.get()};
if (socket.value()) {
return {}; // connection success
Expand All @@ -234,7 +233,7 @@ namespace glz
if (bool(ec)) [[unlikely]] {
return {repe::error_e::invalid_params, glz::format_error(ec, buffer)};
}

unique_socket socket{socket_pool.get()};

try {
Expand All @@ -245,7 +244,7 @@ namespace glz
(*is_connected) = false;
return {repe::error_e::server_error_upper, "asio send failure"};
}

return {};
}

Expand All @@ -261,7 +260,7 @@ namespace glz
if (bool(ec)) [[unlikely]] {
return {repe::error_e::invalid_params, glz::format_error(ec, buffer)};
}

unique_socket socket{socket_pool.get()};

try {
Expand All @@ -272,7 +271,7 @@ namespace glz
(*is_connected) = false;
return {repe::error_e::server_error_upper, "asio send failure"};
}

try {
receive_buffer(*socket, buffer);
}
Expand Down Expand Up @@ -309,7 +308,7 @@ namespace glz
if (bool(ec)) [[unlikely]] {
return {repe::error_e::invalid_params, glz::format_error(ec, buffer)};
}

unique_socket socket{socket_pool.get()};

try {
Expand All @@ -320,7 +319,7 @@ namespace glz
(*is_connected) = false;
return {repe::error_e::server_error_upper, "asio send failure"};
}

try {
receive_buffer(*socket, buffer);
}
Expand All @@ -344,7 +343,7 @@ namespace glz
if (bool(ec)) [[unlikely]] {
return {repe::error_e::invalid_params, glz::format_error(ec, buffer)};
}

unique_socket socket{socket_pool.get()};

try {
Expand All @@ -355,7 +354,7 @@ namespace glz
(*is_connected) = false;
return {repe::error_e::server_error_upper, "asio send failure"};
}

try {
receive_buffer(*socket, buffer);
}
Expand All @@ -379,7 +378,7 @@ namespace glz
if (bool(ec)) [[unlikely]] {
return {repe::error_e::invalid_params, glz::format_error(ec, buffer)};
}

unique_socket socket{socket_pool.get()};

try {
Expand All @@ -390,7 +389,7 @@ namespace glz
(*is_connected) = false;
return {repe::error_e::server_error_upper, "asio send failure"};
}

try {
receive_buffer(*socket, buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/asio_repe/client/repe_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void async_calls()

int main()
{
//asio_client_test();
// asio_client_test();
async_calls();

std::this_thread::sleep_for(std::chrono::seconds(5));
Expand Down

0 comments on commit ee01821

Please sign in to comment.