connection_pool.ipp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MYSQL_IMPL_CONNECTION_POOL_IPP
  8. #define BOOST_MYSQL_IMPL_CONNECTION_POOL_IPP
  9. #pragma once
  10. #include <boost/mysql/connection_pool.hpp>
  11. #include <boost/mysql/detail/connection_pool_fwd.hpp>
  12. #include <boost/mysql/impl/internal/connection_pool/connection_pool_impl.hpp>
  13. #include <boost/asio/any_io_executor.hpp>
  14. #include <memory>
  15. void boost::mysql::detail::return_connection(
  16. pool_impl& pool,
  17. connection_node& node,
  18. bool should_reset
  19. ) noexcept
  20. {
  21. pool.return_connection(node, should_reset);
  22. }
  23. boost::mysql::any_connection& boost::mysql::detail::get_connection(boost::mysql::detail::connection_node& node
  24. ) noexcept
  25. {
  26. return node.connection();
  27. }
  28. boost::mysql::connection_pool::connection_pool(asio::any_io_executor ex, pool_params&& params, int)
  29. : impl_(std::make_shared<detail::pool_impl>(std::move(ex), std::move(params)))
  30. {
  31. }
  32. boost::mysql::connection_pool::executor_type boost::mysql::connection_pool::get_executor() noexcept
  33. {
  34. return impl_->get_executor();
  35. }
  36. void boost::mysql::connection_pool::async_run_erased(
  37. std::shared_ptr<detail::pool_impl> pool,
  38. asio::any_completion_handler<void(error_code)> handler
  39. )
  40. {
  41. pool->async_run(std::move(handler));
  42. }
  43. void boost::mysql::connection_pool::async_get_connection_erased(
  44. std::shared_ptr<detail::pool_impl> pool,
  45. diagnostics* diag,
  46. asio::any_completion_handler<void(error_code, pooled_connection)> handler
  47. )
  48. {
  49. pool->async_get_connection(diag, std::move(handler));
  50. }
  51. void boost::mysql::connection_pool::cancel()
  52. {
  53. BOOST_ASSERT(valid());
  54. impl_->cancel();
  55. }
  56. #endif