src/openssl/src/openssl_stream.cpp

100.0% Lines (47 / 47) 70.6% Branches (12 / 17) 100.0% Functions (16 / 16)
openssl_stream.cpp
f(x) Functions (16)
Function Calls Lines Branches Blocks
boost::corosio::openssl_stream::make_implementation(boost::capy::any_stream, boost::corosio::detail::tls_owned_transport, boost::corosio::tls_context const&) :34 3278x 100.0% 33.3% 57.9% void boost::corosio::(anonymous namespace)::release_driver<boost::corosio::openssl_stream::implementation>(boost::corosio::openssl_stream::implementation*) :50 3285x 100.0% 83.3% 100.0% boost::corosio::openssl_stream::~openssl_stream() :61 3293x 100.0% – 100.0% boost::corosio::openssl_stream::openssl_stream(boost::corosio::openssl_stream&&) :66 6x 100.0% – 100.0% boost::corosio::openssl_stream::operator=(boost::corosio::openssl_stream&&) :72 1x 100.0% 50.0% 100.0% boost::corosio::openssl_stream::next_layer() :83 1x 100.0% – 100.0% boost::corosio::openssl_stream::next_layer() const :89 1x 100.0% – 100.0% boost::corosio::openssl_stream::do_read_some(boost::capy::detail::buffer_array<16ull, false>) :95 31325x 100.0% 100.0% 64.3% boost::corosio::openssl_stream::do_write_some(boost::capy::detail::buffer_array<16ull, true>) :103 31223x 100.0% 100.0% 64.3% boost::corosio::openssl_stream::handshake(boost::corosio::tls_role) :111 2372x 100.0% 100.0% 77.8% boost::corosio::openssl_stream::shutdown() :118 155x 100.0% 100.0% 77.8% boost::corosio::openssl_stream::cancel() :124 2x 100.0% 50.0% 100.0% boost::corosio::openssl_stream::reset() :131 60x 100.0% – 100.0% boost::corosio::openssl_stream::set_hostname(std::basic_string_view<char, std::char_traits<char> >) :137 13x 100.0% – 100.0% boost::corosio::openssl_stream::name() const :143 1x 100.0% – 100.0% boost::corosio::openssl_stream::alpn_protocol() const :149 3x 100.0% – 100.0%
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco ([email protected])
3 // Copyright (c) 2026 Michael Vandeberg
4 // Copyright (c) 2026 Steve Gerbino
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // Official repository: https://github.com/cppalliance/corosio
10 //
11
12 #include <boost/corosio/openssl_stream.hpp>
13 #include <boost/corosio/detail/config.hpp>
14
15 #include "detail/engine.hpp"
16 #include "src/tls/detail/engine_driver.hpp"
17
18 // The driver logic lives once in detail::engine_driver (see its
19 // header for the architecture); this TU only binds it to the OpenSSL
20 // engine and plumbs the public stream surface through.
21
22 namespace boost::corosio {
23
24 // Readable failure if the engine drifts from the driver's surface.
25 static_assert(detail::tls_engine<detail::openssl::engine>);
26
27 struct openssl_stream::implementation
28 : detail::engine_driver<detail::openssl::engine>
29 {
30 using engine_driver::engine_driver;
31 };
32
33 openssl_stream::implementation*
34 3278x openssl_stream::make_implementation(
35 capy::any_stream stream,
36 detail::tls_owned_transport owned,
37 tls_context const& ctx)
38 {
39 // Session creation is deferred to handshake time (the engine's
40 // prepare hook builds it lazily), so a session setup failure
41 // surfaces through the handshake completion instead of leaving a
42 // null implementation behind.
43
1/3
✓ Branch 6 → 7 taken 3278 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
3278x return new implementation(std::move(stream), owned, ctx);
44 }
45
46 namespace {
47
48 template<class Impl>
49 void
50 3285x release_driver(Impl* impl) noexcept
51 {
52
2/2
✓ Branch 2 → 3 taken 7 times.
✓ Branch 2 → 4 taken 3278 times.
3285x if (!impl)
53 7x return;
54 3278x impl->orphan();
55
2/2
✓ Branch 6 → 7 taken 3272 times.
✓ Branch 6 → 10 taken 6 times.
3278x if (impl->release_ref())
56
1/2
✓ Branch 7 → 8 taken 3272 times.
✗ Branch 7 → 10 not taken.
3272x delete impl;
57 }
58
59 } // namespace
60
61 3293x openssl_stream::~openssl_stream()
62 {
63 3284x release_driver(impl_);
64 3293x }
65
66 6x openssl_stream::openssl_stream(openssl_stream&& other) noexcept
67 6x : impl_(std::exchange(other.impl_, nullptr))
68 {
69 6x }
70
71 openssl_stream&
72 1x openssl_stream::operator=(openssl_stream&& other) noexcept
73 {
74
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 6 not taken.
1x if (this != &other)
75 {
76 1x release_driver(impl_);
77 1x impl_ = std::exchange(other.impl_, nullptr);
78 }
79 1x return *this;
80 }
81
82 capy::any_stream&
83 1x openssl_stream::next_layer() noexcept
84 {
85 1x return impl_->stream();
86 }
87
88 capy::any_stream const&
89 1x openssl_stream::next_layer() const noexcept
90 {
91 1x return impl_->stream();
92 }
93
94 capy::task<capy::results<std::size_t>>
95 31325x openssl_stream::do_read_some(
96 capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers)
97 {
98 62650x return detail::driver_read_some(
99
1/1
✓ Branch 4 → 5 taken 31325 times.
62650x detail::driver_ref<implementation>(impl_), buffers);
100 }
101
102 capy::task<capy::results<std::size_t>>
103 31223x openssl_stream::do_write_some(
104 capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers)
105 {
106 62446x return detail::driver_write_some(
107
1/1
✓ Branch 4 → 5 taken 31223 times.
62446x detail::driver_ref<implementation>(impl_), buffers);
108 }
109
110 capy::task<capy::results<>>
111 2372x openssl_stream::handshake(tls_role role)
112 {
113 return detail::driver_handshake(
114
1/1
✓ Branch 3 → 4 taken 2372 times.
2372x detail::driver_ref<implementation>(impl_), role);
115 }
116
117 capy::task<capy::results<>>
118 155x openssl_stream::shutdown()
119 {
120
1/1
✓ Branch 3 → 4 taken 155 times.
155x return detail::driver_shutdown(detail::driver_ref<implementation>(impl_));
121 }
122
123 void
124 2x openssl_stream::cancel() noexcept
125 {
126
1/2
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 4 not taken.
2x if (impl_)
127 2x impl_->cancel_transport();
128 2x }
129
130 void
131 60x openssl_stream::reset()
132 {
133 60x impl_->reset();
134 60x }
135
136 void
137 13x openssl_stream::set_hostname(std::string_view hostname)
138 {
139 13x impl_->set_hostname(hostname);
140 13x }
141
142 std::string_view
143 1x openssl_stream::name() const noexcept
144 {
145 1x return "openssl";
146 }
147
148 std::string_view
149 3x openssl_stream::alpn_protocol() const noexcept
150 {
151 3x return impl_->alpn_protocol();
152 }
153
154 } // namespace boost::corosio
155