morph
0.1.0
Asynchronous bridge between GUI thread and business models
Toggle main menu visibility
Loading...
Searching...
No Matches
connection_writer.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
3
#pragma once
4
#include <cstddef>
5
#include <cstdint>
6
#include <functional>
7
#include <string>
8
9
/// @file
10
/// @brief What a transport hands `RemoteServer` to write to one connection,
11
/// and the backlog bounds both sides apply.
12
///
13
/// Kept apart from `remote.hpp` so a transport's connection code, which both
14
/// the client and the server role share, can use the bounds without compiling
15
/// the server.
16
17
namespace
morph::backend {
18
19
/// @brief Opaque id a transport uses to scope model registrations to one
20
/// connection so `RemoteServer::closeConnection` can reclaim them.
21
///
22
/// `0` is reserved and means *unscoped*: it is what the two-argument
23
/// `RemoteServer::handle()`/`handleInline()` overloads pass. Non-zero values
24
/// are minted by `RemoteServer::openConnection()`.
25
using
ConnectionId
= std::uint64_t;
26
27
/// @brief A transport's outbound side of one connection, for what the server
28
/// sends unasked: events.
29
///
30
/// Handed to `RemoteServer::setConnectionWriter`. Both callables run on the
31
/// server strand, so neither may block: `write` queues the frame on the
32
/// transport's own thread, as a reply is queued.
33
struct
ConnectionWriter
{
34
/// @brief Queues one encoded envelope for the connection. May throw when
35
/// the connection can no longer be written; the server catches it.
36
std::function<void(std::string)>
write
;
37
/// @brief Bytes of encoded envelopes handed to the transport for this
38
/// connection, replies and events alike, and not yet written.
39
/// Empty reads as `0`. May throw; the server catches it and writes
40
/// nothing.
41
std::function<std::size_t()>
backlog
;
42
};
43
44
/// @brief Backlog above which `RemoteServer::post` holds a connection's events
45
/// back and owes it one `resync` instead: 1 MiB.
46
inline
constexpr
std::size_t
kEventBacklogHigh
= std::size_t{1} << 20;
47
48
/// @brief Backlog below which a transport reports a connection drained, by
49
/// calling `RemoteServer::connectionDrained`: 256 KiB.
50
///
51
/// Well under `kEventBacklogHigh`, so a reader hovering at the bound does not
52
/// flip between held back and drained on every frame.
53
inline
constexpr
std::size_t
kEventBacklogLow
= std::size_t{256} << 10;
54
55
}
// namespace morph::backend
morph::backend::kEventBacklogHigh
constexpr std::size_t kEventBacklogHigh
Backlog above which RemoteServer::post holds a connection's events back and owes it one resync instea...
Definition
connection_writer.hpp:46
morph::backend::ConnectionId
std::uint64_t ConnectionId
Opaque id a transport uses to scope model registrations to one connection so RemoteServer::closeConne...
Definition
connection_writer.hpp:25
morph::backend::kEventBacklogLow
constexpr std::size_t kEventBacklogLow
Backlog below which a transport reports a connection drained, by calling RemoteServer::connectionDrai...
Definition
connection_writer.hpp:53
morph::backend::ConnectionWriter
A transport's outbound side of one connection, for what the server sends unasked: events.
Definition
connection_writer.hpp:33
morph::backend::ConnectionWriter::write
std::function< void(std::string)> write
Queues one encoded envelope for the connection. May throw when the connection can no longer be writte...
Definition
connection_writer.hpp:36
morph::backend::ConnectionWriter::backlog
std::function< std::size_t()> backlog
Bytes of encoded envelopes handed to the transport for this connection, replies and events alike,...
Definition
connection_writer.hpp:41
morph
core
connection_writer.hpp
Generated by
1.17.0