Malloy
Loading...
Searching...
No Matches
connection_plain.hpp
1#pragma once
2
3#include "connection.hpp"
4#include "../../core/tcp/stream.hpp"
5
6namespace malloy::server::http
7{
8
13 public connection<connection_plain>,
14 public std::enable_shared_from_this<connection_plain>
15 {
16 friend connection;
17
18 public:
19 // Create the session
21 std::shared_ptr<spdlog::logger> logger,
22 boost::asio::ip::tcp::socket&& socket,
23 boost::beast::flat_buffer buffer,
24 std::shared_ptr<const std::filesystem::path> doc_root,
25 std::shared_ptr<handler> router
26 ) :
28 std::move(logger),
29 std::move(buffer),
30 std::move(router),
31 std::move(doc_root)
32 ),
33 m_stream(std::move(socket))
34 {
35 }
36
37 // Called by the base class
38 [[nodiscard]]
40 stream()
41 {
42 return m_stream;
43 }
44
50 [[nodiscard]]
53 {
54 return std::move(m_stream);
55 }
56
60 void
62 {
63 // We need to be executing within a strand to perform async operations
64 // on the I/O objects in this session. Although not strictly necessary
65 // for single-threaded contexts, this example code is written to be
66 // thread-safe by default.
67 boost::asio::dispatch(m_stream.get_executor(),
68 boost::beast::bind_front_handler(
69 &connection_plain::do_read,
70 shared_from_this()
71 )
72 );
73 }
74
78 void
80 {
81 // Send a TCP shutdown
82 boost::beast::error_code ec;
83 m_stream.socket().shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec);
84
85 // At this point the connection is closed gracefully
86 }
87
88 private:
89 malloy::tcp::stream<> m_stream;
90 };
91
92}
Definition: connection_plain.hpp:15
void run()
Definition: connection_plain.hpp:61
void do_close()
Definition: connection_plain.hpp:79
malloy::tcp::stream release_stream()
Definition: connection_plain.hpp:52
Definition: connection.hpp:41
std::shared_ptr< spdlog::logger > logger() const noexcept
Definition: connection.hpp:184
Definition: router.hpp:103
boost::beast::basic_stream< boost::asio::ip::tcp, boost::asio::any_io_executor, RatePolicy > stream
Definition: stream.hpp:22