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