Malloy
Loading...
Searching...
No Matches
connection_tls.hpp
1#pragma once
2
3#include "connection.hpp"
4#include "../../core/tcp/stream.hpp"
5
6#include <boost/beast/ssl/ssl_stream.hpp>
7
8namespace malloy::client::http
9{
10
14 template<typename... ConnArgs>
16 public connection<connection_tls<ConnArgs...>, ConnArgs...>,
17 public std::enable_shared_from_this<connection_tls<ConnArgs...>>
18 {
19 using parent_t = connection<connection_tls<ConnArgs...>, ConnArgs...>;
20
21 public:
23 std::shared_ptr<spdlog::logger> logger,
24 boost::asio::io_context& io_ctx,
25 boost::asio::ssl::context& tls_ctx,
26 const std::uint64_t body_limit
27 ) :
28 parent_t(std::move(logger), body_limit),
29 m_stream(boost::asio::make_strand(io_ctx), tls_ctx) // ToDo: make_strand() necessary since we're using coroutines?
30 {
31 }
32
33 // Called by base class
34 [[nodiscard]]
35 boost::beast::ssl_stream<malloy::tcp::stream<>>&
36 stream()
37 {
38 return m_stream;
39 }
40
41 // ToDo: Return error code!
42 boost::asio::awaitable<void>
43 hook_connected()
44 {
45 // Perform the TLS handshake
46 parent_t::set_stream_timeout(std::chrono::seconds(30)); // ToDo: Do not hard-code!
47 co_await m_stream.async_handshake(boost::asio::ssl::stream_base::client);
48 }
49
50 private:
51 boost::beast::ssl_stream<malloy::tcp::stream<>> m_stream;
52 };
53}
Definition: connection_tls.hpp:18
Definition: connection.hpp:34