include/boost/burl/detail/connection_pool.hpp
100.0% Lines (18/18)
100.0% List of functions (10/10)
100.0% Branches (2/2)
Functions (10)
Function
Calls
Lines
Branches
Blocks
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::read_some<boost::capy::mutable_buffer>(boost::capy::mutable_buffer)
:45
33x
100.0%
100.0%
75.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::read_some<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> >(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>)
:45
203x
100.0%
100.0%
75.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::write_some<boost::capy::const_buffer>(boost::capy::const_buffer)
:52
1x
100.0%
100.0%
75.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::write_some<std::span<boost::capy::const_buffer const, 18446744073709551615ul> >(std::span<boost::capy::const_buffer const, 18446744073709551615ul>)
:52
45x
100.0%
100.0%
75.0%
boost::burl::detail::connection::set_io_timeout(std::optional<std::chrono::duration<long, std::ratio<1l, 1000000000l> > >)
:58
61x
100.0%
–
100.0%
boost::burl::detail::connection::~connection()
:69
138x
100.0%
–
100.0%
boost::burl::detail::pooled_connection::pooled_connection()
:95
10x
100.0%
–
100.0%
boost::burl::detail::pooled_connection::stream()
:98
117x
100.0%
–
100.0%
boost::burl::detail::pooled_connection::operator bool() const
:104
249x
100.0%
–
100.0%
boost::burl::detail::pooled_connection::pooled_connection(std::unique_ptr<boost::burl::detail::connection, std::default_delete<boost::burl::detail::connection> >, std::weak_ptr<boost::burl::detail::connection_pool>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
:114
131x
100.0%
–
100.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2026 Mohammad Nejati | |||
| 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 | // Official repository: https://github.com/cppalliance/burl | |||
| 8 | // | |||
| 9 | ||||
| 10 | #ifndef BOOST_BURL_DETAIL_CONNECTION_POOL_HPP | |||
| 11 | #define BOOST_BURL_DETAIL_CONNECTION_POOL_HPP | |||
| 12 | ||||
| 13 | #include <boost/burl/detail/config.hpp> | |||
| 14 | #include <boost/burl/test/fwd.hpp> | |||
| 15 | #include <boost/capy/buffers.hpp> | |||
| 16 | #include <boost/capy/detail/buffer_array.hpp> | |||
| 17 | #include <boost/capy/io/any_stream.hpp> | |||
| 18 | #include <boost/capy/io_task.hpp> | |||
| 19 | ||||
| 20 | #include <chrono> | |||
| 21 | #include <cstddef> | |||
| 22 | #include <memory> | |||
| 23 | #include <optional> | |||
| 24 | #include <span> | |||
| 25 | #include <string> | |||
| 26 | #include <utility> | |||
| 27 | ||||
| 28 | namespace boost | |||
| 29 | { | |||
| 30 | namespace burl | |||
| 31 | { | |||
| 32 | namespace detail | |||
| 33 | { | |||
| 34 | ||||
| 35 | class connection_pool; | |||
| 36 | ||||
| 37 | class connection | |||
| 38 | { | |||
| 39 | using duration = std::chrono::steady_clock::duration; | |||
| 40 | std::optional<duration> io_timeout_; | |||
| 41 | ||||
| 42 | public: | |||
| 43 | template<capy::MutableBufferSequence MB> | |||
| 44 | capy::io_task<std::size_t> | |||
| 45 | 236x | read_some(MB buffers) | ||
| 46 | { | |||
| 47 |
1/1✓ Branch 2 taken 236 times.
|
236x | return read_some_impl(buffers); | |
| 48 | } | |||
| 49 | ||||
| 50 | template<capy::ConstBufferSequence CB> | |||
| 51 | capy::io_task<std::size_t> | |||
| 52 | 46x | write_some(CB buffers) | ||
| 53 | { | |||
| 54 |
1/1✓ Branch 2 taken 46 times.
|
46x | return write_some_impl(buffers); | |
| 55 | } | |||
| 56 | ||||
| 57 | void | |||
| 58 | 61x | set_io_timeout(std::optional<duration> io_timeout) noexcept | ||
| 59 | { | |||
| 60 | 61x | io_timeout_ = io_timeout; | ||
| 61 | 61x | } | ||
| 62 | ||||
| 63 | virtual bool | |||
| 64 | is_open() const noexcept = 0; | |||
| 65 | ||||
| 66 | // virtual capy::io_task<> | |||
| 67 | // shutdown() = 0; | |||
| 68 | ||||
| 69 | 138x | virtual ~connection() = default; | ||
| 70 | ||||
| 71 | private: | |||
| 72 | capy::io_task<std::size_t> | |||
| 73 | read_some_impl(capy::detail::mutable_buffer_array<8>); | |||
| 74 | ||||
| 75 | capy::io_task<std::size_t> | |||
| 76 | write_some_impl(capy::detail::const_buffer_array<8>); | |||
| 77 | ||||
| 78 | virtual capy::io_task<std::size_t> | |||
| 79 | do_read_some(std::span<capy::mutable_buffer const> buffers) = 0; | |||
| 80 | ||||
| 81 | virtual capy::io_task<std::size_t> | |||
| 82 | do_write_some(std::span<capy::const_buffer const> buffers) = 0; | |||
| 83 | }; | |||
| 84 | ||||
| 85 | class pooled_connection | |||
| 86 | { | |||
| 87 | friend class connection_pool; | |||
| 88 | friend class test::response_factory; | |||
| 89 | ||||
| 90 | std::unique_ptr<connection> conn_; | |||
| 91 | std::weak_ptr<connection_pool> pool_; | |||
| 92 | std::string key_; | |||
| 93 | ||||
| 94 | public: | |||
| 95 | 10x | pooled_connection() = default; | ||
| 96 | ||||
| 97 | capy::any_stream | |||
| 98 | 117x | stream() noexcept | ||
| 99 | { | |||
| 100 | 117x | return conn_.get(); | ||
| 101 | } | |||
| 102 | ||||
| 103 | explicit | |||
| 104 | 249x | operator bool() const noexcept | ||
| 105 | { | |||
| 106 | 249x | return conn_ != nullptr; | ||
| 107 | } | |||
| 108 | ||||
| 109 | BOOST_BURL_DECL | |||
| 110 | void | |||
| 111 | return_to_pool(); | |||
| 112 | ||||
| 113 | private: | |||
| 114 | 131x | pooled_connection( | ||
| 115 | std::unique_ptr<connection> conn, | |||
| 116 | std::weak_ptr<connection_pool> pool, | |||
| 117 | std::string key) | |||
| 118 | 131x | : conn_(std::move(conn)) | ||
| 119 | 131x | , pool_(std::move(pool)) | ||
| 120 | 131x | , key_(std::move(key)) | ||
| 121 | { | |||
| 122 | 131x | } | ||
| 123 | }; | |||
| 124 | ||||
| 125 | } // namespace detail | |||
| 126 | } // namespace burl | |||
| 127 | } // namespace boost | |||
| 128 | ||||
| 129 | #endif | |||
| 130 |