Malloy
Toggle main menu visibility
Loading...
Searching...
No Matches
lib
malloy
server
http
connection_plain.hpp
1
#pragma once
2
3
#include "connection.hpp"
4
#include "../../core/tcp/stream.hpp"
5
6
namespace
malloy::server::http
7
{
8
12
class
connection_plain :
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
20
connection_plain(
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
) :
27
connection<connection_plain>(
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]]
39
malloy::tcp::stream<>
&
40
stream()
41
{
42
return
m_stream;
43
}
44
50
[[nodiscard]]
51
malloy::tcp::stream<>
52
release_stream
()
53
{
54
return
std::move(m_stream);
55
}
56
60
void
61
run
()
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
79
do_close
()
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
}
malloy::server::http::connection_plain::run
void run()
Definition
connection_plain.hpp:61
malloy::server::http::connection_plain::do_close
void do_close()
Definition
connection_plain.hpp:79
malloy::server::http::connection_plain::release_stream
malloy::tcp::stream release_stream()
Definition
connection_plain.hpp:52
malloy::server::http::connection< connection_plain >::logger
std::shared_ptr< spdlog::logger > logger() const noexcept
Definition
connection.hpp:184
malloy::server::router
Definition
router.hpp:103
malloy::tcp::stream
boost::beast::basic_stream< boost::asio::ip::tcp, boost::asio::any_io_executor, RatePolicy > stream
Definition
stream.hpp:18
Generated by
1.18.0