include/boost/burl/detail/connection_pool.hpp
100.0% Lines (24/24)
100.0% List of functions (17/17)
100.0% Branches (10/10)
Functions (17)
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
35x
100.0%
100.0%
100.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::read_some<boost::span<boost::capy::mutable_buffer const, 18446744073709551615ul> >(boost::span<boost::capy::mutable_buffer const, 18446744073709551615ul>)
:45
128x
100.0%
100.0%
100.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
8x
100.0%
100.0%
100.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::write_some<boost::capy::const_buffer>(boost::capy::const_buffer)
:53
1x
100.0%
100.0%
100.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::write_some<boost::capy::detail::slice_impl<boost::capy::const_buffer>::data_view>(boost::capy::detail::slice_impl<boost::capy::const_buffer>::data_view)
:53
41x
100.0%
100.0%
100.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::write_some<boost::capy::mutable_buffer>(boost::capy::mutable_buffer)
:53
1x
100.0%
100.0%
100.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::connection::write_some<boost::span<boost::capy::const_buffer const, 18446744073709551615ul> >(boost::span<boost::capy::const_buffer const, 18446744073709551615ul>)
:53
2x
100.0%
100.0%
100.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>)
:53
8x
100.0%
100.0%
100.0%
boost::burl::detail::connection::~connection()
:65
148x
100.0%
–
100.0%
boost::burl::detail::pooled_connection::pooled_connection()
:88
13x
80.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)
:92
2x
100.0%
100.0%
86.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::pooled_connection::read_some<boost::span<boost::capy::mutable_buffer const, 18446744073709551615ul> >(boost::span<boost::capy::mutable_buffer const, 18446744073709551615ul>)
:92
128x
75.0%
25.0%
43.0%
boost::capy::task<boost::capy::io_result<unsigned long> > boost::burl::detail::pooled_connection::read_some<std::span<boost::capy::mutable_buffer const, 18446744073709551615ul> >(std::span<boost::capy::mutable_buffer const, 18446744073709551615ul>)
:92
8x
75.0%
25.0%
43.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)
:101
1x
75.0%
75.0%
71.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>)
:101
8x
75.0%
25.0%
43.0%
boost::burl::detail::pooled_connection::operator bool() const
:109
229x
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> >, std::optional<std::chrono::duration<long, std::ratio<1l, 1000000000l> > >)
:119
140x
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 | #include <boost/capy/timeout.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 | capy::detail::buffer_array<8, false> rba_; // TODO | |||
| 40 | capy::detail::buffer_array<8, true> wba_; // TODO | |||
| 41 | ||||
| 42 | public: | |||
| 43 | template<capy::MutableBufferSequence MB> | |||
| 44 | capy::io_task<std::size_t> | |||
| 45 | 171x | read_some(MB buffers) | ||
| 46 | { | |||
| 47 | 171x | rba_ = buffers; | ||
| 48 |
1/1✓ Branch 2 taken 171 times.
|
171x | return do_read_some(rba_); | |
| 49 | } | |||
| 50 | ||||
| 51 | template<capy::ConstBufferSequence CB> | |||
| 52 | capy::io_task<std::size_t> | |||
| 53 | 53x | write_some(CB buffers) | ||
| 54 | { | |||
| 55 | 53x | wba_ = buffers; | ||
| 56 |
1/1✓ Branch 2 taken 53 times.
|
53x | return do_write_some(wba_); | |
| 57 | } | |||
| 58 | ||||
| 59 | virtual bool | |||
| 60 | is_open() const noexcept = 0; | |||
| 61 | ||||
| 62 | // virtual capy::io_task<> | |||
| 63 | // shutdown() = 0; | |||
| 64 | ||||
| 65 | 148x | virtual ~connection() = default; | ||
| 66 | ||||
| 67 | private: | |||
| 68 | virtual capy::io_task<std::size_t> | |||
| 69 | do_read_some(std::span<capy::mutable_buffer const> buffers) = 0; | |||
| 70 | ||||
| 71 | virtual capy::io_task<std::size_t> | |||
| 72 | do_write_some(std::span<capy::const_buffer const> buffers) = 0; | |||
| 73 | }; | |||
| 74 | ||||
| 75 | class pooled_connection | |||
| 76 | { | |||
| 77 | friend class connection_pool; | |||
| 78 | friend class test::response_factory; | |||
| 79 | ||||
| 80 | using duration = std::chrono::steady_clock::duration; | |||
| 81 | ||||
| 82 | std::unique_ptr<connection> conn_; | |||
| 83 | std::weak_ptr<connection_pool> pool_; | |||
| 84 | std::string key_; | |||
| 85 | std::optional<duration> io_timeout_; | |||
| 86 | ||||
| 87 | public: | |||
| 88 | 13x | pooled_connection() = default; | ||
| 89 | ||||
| 90 | template<capy::MutableBufferSequence MB> | |||
| 91 | capy::io_task<std::size_t> | |||
| 92 | 138x | read_some(MB buffers) | ||
| 93 | { | |||
| 94 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 137 times.
|
138x | if(io_timeout_) | |
| 95 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1x | return capy::timeout(conn_->read_some(buffers), *io_timeout_); | |
| 96 | 137x | return conn_->read_some(buffers); | ||
| 97 | } | |||
| 98 | ||||
| 99 | template<capy::ConstBufferSequence CB> | |||
| 100 | capy::io_task<std::size_t> | |||
| 101 | 52x | write_some(CB buffers) | ||
| 102 | { | |||
| 103 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 8 times.
|
52x | if(io_timeout_) | |
| 104 |
2/2✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
|
1x | return capy::timeout(conn_->write_some(buffers), *io_timeout_); | |
| 105 | 51x | return conn_->write_some(buffers); | ||
| 106 | } | |||
| 107 | ||||
| 108 | explicit | |||
| 109 | 229x | operator bool() const noexcept | ||
| 110 | { | |||
| 111 | 229x | return conn_ != nullptr; | ||
| 112 | } | |||
| 113 | ||||
| 114 | BOOST_BURL_DECL | |||
| 115 | void | |||
| 116 | return_to_pool(); | |||
| 117 | ||||
| 118 | private: | |||
| 119 | 140x | pooled_connection( | ||
| 120 | std::unique_ptr<connection> conn, | |||
| 121 | std::weak_ptr<connection_pool> pool, | |||
| 122 | std::string key, | |||
| 123 | std::optional<duration> io_timeout = std::nullopt) | |||
| 124 | 140x | : conn_(std::move(conn)) | ||
| 125 | 140x | , pool_(std::move(pool)) | ||
| 126 | 140x | , key_(std::move(key)) | ||
| 127 | 140x | , io_timeout_(io_timeout) | ||
| 128 | { | |||
| 129 | 140x | } | ||
| 130 | }; | |||
| 131 | ||||
| 132 | } // namespace detail | |||
| 133 | } // namespace burl | |||
| 134 | } // namespace boost | |||
| 135 | ||||
| 136 | #endif | |||
| 137 |