src/openssl/src/openssl_stream.cpp

100.0% Lines (45 / 45) 100.0% Functions (16 / 16)
openssl_stream.cpp
f(x) Functions (16)
Function Calls Lines Blocks
boost::corosio::openssl_stream::make_implementation(boost::capy::any_stream, boost::corosio::detail::tls_owned_transport, boost::corosio::tls_context const&) :34 2294x 100.0% 58.0% void boost::corosio::(anonymous namespace)::release_driver<boost::corosio::openssl_stream::implementation>(boost::corosio::openssl_stream::implementation*) :50 2301x 100.0% 100.0% boost::corosio::openssl_stream::~openssl_stream() :61 2309x 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% 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 36882x 100.0% 64.0% boost::corosio::openssl_stream::do_write_some(boost::capy::detail::buffer_array<16ul, true>) :103 36931x 100.0% 64.0% boost::corosio::openssl_stream::handshake(boost::corosio::tls_role) :111 1748x 100.0% 78.0% boost::corosio::openssl_stream::shutdown() :118 149x 100.0% 78.0% boost::corosio::openssl_stream::cancel() :124 2x 100.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 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 2294x 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 2294x return new implementation(std::move(stream), owned, ctx);
44 }
45
46 namespace {
47
48 template<class Impl>
49 void
50 2301x release_driver(Impl* impl) noexcept
51 {
52 2301x if (!impl)
53 7x return;
54 2294x impl->orphan();
55 2294x if (impl->release_ref())
56 2288x delete impl;
57 }
58
59 } // namespace
60
61 2309x openssl_stream::~openssl_stream()
62 {
63 2300x release_driver(impl_);
64 2309x }
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 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 36882x openssl_stream::do_read_some(
96 capy::detail::mutable_buffer_array<capy::detail::max_iovec_> buffers)
97 {
98 return detail::driver_read_some(
99 73764x detail::driver_ref<implementation>(impl_), buffers);
100 }
101
102 capy::task<capy::results<std::size_t>>
103 36931x openssl_stream::do_write_some(
104 capy::detail::const_buffer_array<capy::detail::max_iovec_> buffers)
105 {
106 return detail::driver_write_some(
107 73862x detail::driver_ref<implementation>(impl_), buffers);
108 }
109
110 capy::task<capy::results<>>
111 1748x openssl_stream::handshake(tls_role role)
112 {
113 return detail::driver_handshake(
114 1748x detail::driver_ref<implementation>(impl_), role);
115 }
116
117 capy::task<capy::results<>>
118 149x openssl_stream::shutdown()
119 {
120 149x return detail::driver_shutdown(detail::driver_ref<implementation>(impl_));
121 }
122
123 void
124 2x openssl_stream::cancel() noexcept
125 {
126 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