connection.ipp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (c) 2018-2025 Marcelo Zimbres Silva (mzimbres@gmail.com)
  2. *
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE.txt)
  5. */
  6. #include <boost/redis/connection.hpp>
  7. #include <boost/redis/impl/log_to_file.hpp>
  8. #include <cstddef>
  9. #include <cstdio>
  10. #include <string_view>
  11. #include <utility>
  12. namespace boost::redis {
  13. logger detail::make_stderr_logger(logger::level lvl, std::string prefix)
  14. {
  15. return logger(lvl, [prefix = std::move(prefix)](logger::level, std::string_view msg) {
  16. log_to_file(stderr, msg, prefix.c_str());
  17. });
  18. }
  19. connection::connection(executor_type ex, asio::ssl::context ctx, logger lgr)
  20. : impl_{std::move(ex), std::move(ctx), std::move(lgr)}
  21. { }
  22. void connection::async_run_impl(
  23. config const& cfg,
  24. logger&& l,
  25. asio::any_completion_handler<void(boost::system::error_code)> token)
  26. {
  27. // Avoid calling the basic_connection::async_run overload taking a logger
  28. // because it generates deprecated messages when building this file
  29. impl_.set_stderr_logger(l.lvl, cfg);
  30. impl_.async_run(cfg, std::move(token));
  31. }
  32. void connection::async_run_impl(
  33. config const& cfg,
  34. asio::any_completion_handler<void(boost::system::error_code)> token)
  35. {
  36. impl_.async_run(cfg, std::move(token));
  37. }
  38. void connection::async_exec_impl(
  39. request const& req,
  40. any_adapter&& adapter,
  41. asio::any_completion_handler<void(boost::system::error_code, std::size_t)> token)
  42. {
  43. impl_.async_exec(req, std::move(adapter), std::move(token));
  44. }
  45. void connection::cancel(operation op) { impl_.cancel(op); }
  46. } // namespace boost::redis