Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions include/boost/redis/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <boost/redis/adapter/adapt.hpp>
#include <boost/redis/adapter/any_adapter.hpp>
#include <boost/redis/config.hpp>
#include <boost/redis/detail/connection_logger.hpp>
#include <boost/redis/detail/connection_state.hpp>
#include <boost/redis/detail/exec_fsm.hpp>
#include <boost/redis/detail/multiplexer.hpp>
Expand Down Expand Up @@ -138,7 +137,7 @@ struct connection_impl {
, reconnect_timer_{ex}
, ping_timer_{ex}
, receive_channel_{ex, 256}
, st_{std::move(lgr)}
, st_{{std::move(lgr)}}
{
set_receive_adapter(any_adapter{ignore});
writer_cv_.expires_at((std::chrono::steady_clock::time_point::max)());
Expand Down Expand Up @@ -863,7 +862,7 @@ class basic_connection {
// Used by both this class and connection
void set_stderr_logger(logger::level lvl, const config& cfg)
{
impl_->st_.logger.reset(detail::make_stderr_logger(lvl, cfg.log_prefix));
impl_->st_.logger.lgr = detail::make_stderr_logger(lvl, cfg.log_prefix);
}

// Initiation for async_run. This is required because we need access
Expand Down
6 changes: 3 additions & 3 deletions include/boost/redis/detail/connect_fsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace boost::redis::detail {

class connection_logger;
struct buffered_logger;

// What transport is redis_stream using?
enum class transport_type
Expand Down Expand Up @@ -63,10 +63,10 @@ struct connect_action {
class connect_fsm {
int resume_point_{0};
const config* cfg_{nullptr};
connection_logger* lgr_{nullptr};
buffered_logger* lgr_{nullptr};

public:
connect_fsm(const config& cfg, connection_logger& lgr) noexcept
connect_fsm(const config& cfg, buffered_logger& lgr) noexcept
: cfg_(&cfg)
, lgr_(&lgr)
{ }
Expand Down
53 changes: 0 additions & 53 deletions include/boost/redis/detail/connection_logger.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions include/boost/redis/detail/connection_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define BOOST_REDIS_CONNECTION_STATE_HPP

#include <boost/redis/config.hpp>
#include <boost/redis/detail/connection_logger.hpp>
#include <boost/redis/detail/multiplexer.hpp>
#include <boost/redis/logger.hpp>
#include <boost/redis/request.hpp>
#include <boost/redis/response.hpp>

Expand All @@ -22,7 +22,7 @@ namespace boost::redis::detail {
// Contains all the members in connection that don't depend on the Executor.
// Makes implementing sans-io algorithms easier
struct connection_state {
connection_logger logger;
buffered_logger logger;
config cfg{};
multiplexer mpx{};
std::string setup_diagnostic{};
Expand Down
4 changes: 2 additions & 2 deletions include/boost/redis/detail/redis_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <boost/redis/config.hpp>
#include <boost/redis/detail/connect_fsm.hpp>
#include <boost/redis/detail/connection_logger.hpp>
#include <boost/redis/error.hpp>
#include <boost/redis/logger.hpp>

#include <boost/asio/basic_waitable_timer.hpp>
#include <boost/asio/cancel_after.hpp>
Expand Down Expand Up @@ -170,7 +170,7 @@ class redis_stream {

// I/O
template <class CompletionToken>
auto async_connect(const config& cfg, connection_logger& l, CompletionToken&& token)
auto async_connect(const config& cfg, buffered_logger& l, CompletionToken&& token)
{
return asio::async_compose<CompletionToken, void(system::error_code)>(
connect_op{*this, connect_fsm(cfg, l)},
Expand Down
5 changes: 1 addition & 4 deletions include/boost/redis/detail/run_fsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#ifndef BOOST_REDIS_RUN_FSM_HPP
#define BOOST_REDIS_RUN_FSM_HPP

#include <boost/redis/detail/connection_state.hpp>

#include <boost/asio/cancellation_type.hpp>
#include <boost/system/error_code.hpp>

Expand All @@ -19,8 +17,7 @@
namespace boost::redis::detail {

// Forward decls
class connection_logger;
class multiplexer;
struct connection_state;

// What should we do next?
enum class run_action_type
Expand Down
6 changes: 2 additions & 4 deletions include/boost/redis/detail/writer_fsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#ifndef BOOST_REDIS_WRITER_FSM_HPP
#define BOOST_REDIS_WRITER_FSM_HPP

#include <boost/redis/detail/connection_state.hpp>

#include <boost/asio/cancellation_type.hpp>
#include <boost/assert.hpp>
#include <boost/system/error_code.hpp>

#include <chrono>
Expand All @@ -22,8 +21,7 @@
namespace boost::redis::detail {

// Forward decls
class connection_logger;
class multiplexer;
struct connection_state;

// What should we do next?
enum class writer_action_type
Expand Down
69 changes: 64 additions & 5 deletions include/boost/redis/impl/connect_fsm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,59 @@

#include <boost/redis/config.hpp>
#include <boost/redis/detail/connect_fsm.hpp>
#include <boost/redis/detail/connection_logger.hpp>
#include <boost/redis/detail/coroutine.hpp>
#include <boost/redis/error.hpp>
#include <boost/redis/impl/log_utils.hpp>

#include <boost/asio/cancellation_type.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/assert.hpp>

#include <string>

namespace boost::redis::detail {

// Logging
inline void format_tcp_endpoint(const asio::ip::tcp::endpoint& ep, std::string& to)
{
// This formatting is inspired by Asio's endpoint operator<<
const auto& addr = ep.address();
if (addr.is_v6())
to += '[';
to += addr.to_string();
if (addr.is_v6())
to += ']';
to += ':';
to += std::to_string(ep.port());
}

template <>
struct log_traits<asio::ip::tcp::endpoint> {
static inline void log(std::string& to, const asio::ip::tcp::endpoint& value)
{
format_tcp_endpoint(value, to);
}
};

template <>
struct log_traits<asio::ip::tcp::resolver::results_type> {
static inline void log(std::string& to, const asio::ip::tcp::resolver::results_type& value)
{
auto iter = value.cbegin();
auto end = value.cend();

if (iter != end) {
format_tcp_endpoint(iter->endpoint(), to);
++iter;
for (; iter != end; ++iter) {
to += ", ";
format_tcp_endpoint(iter->endpoint(), to);
}
}
}
};

inline transport_type transport_from_config(const config& cfg)
{
if (cfg.unix_socket.empty()) {
Expand Down Expand Up @@ -61,7 +104,11 @@ connect_action connect_fsm::resume(
ec = translate_timeout_error(ec, cancel_state, error::resolve_timeout);

// Log it
lgr_->on_resolve(ec, resolver_results);
if (ec) {
log_info(*lgr_, "Error resolving the server hostname: ", ec);
} else {
log_info(*lgr_, "Resolve results: ", resolver_results);
}

// Delegate to the regular resume function
return resume(ec, st, cancel_state);
Expand All @@ -77,7 +124,11 @@ connect_action connect_fsm::resume(
ec = translate_timeout_error(ec, cancel_state, error::connect_timeout);

// Log it
lgr_->on_connect(ec, selected_endpoint);
if (ec) {
log_info(*lgr_, "Failed to connect to the server: ", ec);
} else {
log_info(*lgr_, "Connected to ", selected_endpoint);
}

// Delegate to the regular resume function
return resume(ec, st, cancel_state);
Expand Down Expand Up @@ -108,7 +159,11 @@ connect_action connect_fsm::resume(
ec = translate_timeout_error(ec, cancel_state, error::connect_timeout);

// Log it
lgr_->on_connect(ec, cfg_->unix_socket);
if (ec) {
log_info(*lgr_, "Failed to connect to the server: ", ec);
} else {
log_info(*lgr_, "Connected to ", cfg_->unix_socket);
}

// If this failed, we can't continue
if (ec) {
Expand Down Expand Up @@ -156,7 +211,11 @@ connect_action connect_fsm::resume(
ec = translate_timeout_error(ec, cancel_state, error::ssl_handshake_timeout);

// Log it
lgr_->on_ssl_handshake(ec);
if (ec) {
log_info(*lgr_, "Failed to perform SSL handshake: ", ec);
} else {
log_info(*lgr_, "Successfully performed SSL handshake");
}

// If this failed, we can't continue
if (ec) {
Expand Down
Loading