src/openssl/src/openssl_stream.cpp

91.2% Lines (52 / 57) 54.2% Branches (13 / 24) 100.0% Functions (18 / 18)
openssl_stream.cpp
f(x) Functions (18)
Function Calls Lines Branches Blocks
boost::corosio::openssl_stream::implementation::~implementation() :27 5636x 100.0% – 100.0% boost::corosio::openssl_stream::implementation::implementation(boost::capy::any_stream, boost::corosio::detail::tls_owned_transport, boost::corosio::tls_context) :30 5636x 100.0% – 100.0% boost::corosio::openssl_stream::make_implementation(boost::capy::any_stream, boost::corosio::detail::tls_owned_transport, boost::corosio::tls_context const&) :34 2818x 66.7% 25.0% 33.0% void boost::corosio::(anonymous namespace)::release_driver<boost::corosio::openssl_stream::implementation>(boost::corosio::openssl_stream::implementation*) :50 2829x 100.0% 83.3% 100.0% boost::corosio::openssl_stream::~openssl_stream() :61 5656x 100.0% – 100.0% boost::corosio::openssl_stream::openssl_stream(boost::corosio::openssl_stream&&) :66 20x 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<16ul, false>) :95 116498x 75.0% 50.0% 50.0% boost::corosio::openssl_stream::do_write_some(boost::capy::detail::buffer_array<16ul, true>) :103 116432x 75.0% 50.0% 50.0% boost::corosio::openssl_stream::handshake(boost::corosio::tls_role) :111 2102x 75.0% 50.0% 50.0% boost::corosio::openssl_stream::shutdown() :118 146x 66.7% 50.0% 50.0% 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::__1::basic_string_view<char, std::__1::char_traits<char>>) :137 15x 100.0% – 100.0% boost::corosio::openssl_stream::name() const :143 1x 100.0% 50.0% 66.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 2818x 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/4
✓ Branch 0 taken 2818 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2818x return new implementation(std::move(stream), owned, ctx);
44 ✗ }
45
46 namespace {
47
48 template<class Impl>
49 void
50 2829x release_driver(Impl* impl) noexcept
51 {
52
2/2
✓ Branch 0 taken 2818 times.
✓ Branch 1 taken 11 times.
2829x if (!impl)
53 11x return;
54 2818x impl->orphan();
55
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2812 times.
2818x if (impl->release_ref())
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2812 times.
2812x delete impl;
57 2829x }
58
59 } // namespace
60
61 5656x openssl_stream::~openssl_stream()
62 2828x {
63 2828x release_driver(impl_);
64 5656x }
65
66 20x openssl_stream::openssl_stream(openssl_stream&& other) noexcept
67 10x : impl_(std::exchange(other.impl_, nullptr))
68 20x {
69 20x }
70
71 openssl_stream&
72 1x openssl_stream::operator=(openssl_stream&& other) noexcept
73 {
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1x if (this != &other)
75 {
76 1x release_driver(impl_);
77 1x impl_ = std::exchange(other.impl_, nullptr);
78 1x }
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 116498x openssl_stream::do_read_some(
96 capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers)
97 {
98
1/2
✓ Branch 0 taken 116498 times.
✗ Branch 1 not taken.
116498x return detail::driver_read_some(
99 116498x detail::driver_ref<implementation>(impl_), buffers);
100 ✗ }
101
102 capy::task<capy::results<std::size_t>>
103 116432x openssl_stream::do_write_some(
104 capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers)
105 {
106
1/2
✓ Branch 0 taken 116432 times.
✗ Branch 1 not taken.
116432x return detail::driver_write_some(
107 116432x detail::driver_ref<implementation>(impl_), buffers);
108 ✗ }
109
110 capy::task<capy::results<>>
111 2102x openssl_stream::handshake(tls_role role)
112 {
113
1/2
✓ Branch 0 taken 2102 times.
✗ Branch 1 not taken.
2102x return detail::driver_handshake(
114 2102x detail::driver_ref<implementation>(impl_), role);
115 ✗ }
116
117 capy::task<capy::results<>>
118 146x openssl_stream::shutdown()
119 {
120
1/2
✓ Branch 0 taken 146 times.
✗ Branch 1 not taken.
146x return detail::driver_shutdown(detail::driver_ref<implementation>(impl_));
121 ✗ }
122
123 void
124 2x openssl_stream::cancel() noexcept
125 {
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
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 15x openssl_stream::set_hostname(std::string_view hostname)
138 {
139 15x impl_->set_hostname(hostname);
140 15x }
141
142 std::string_view
143 1x openssl_stream::name() const noexcept
144 {
145
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
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