userver
C++ Async Framework
Loading...
Searching...
No Matches
stream.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/ugrpc/server/stream.hpp
4
/// @brief Server streaming interfaces
5
6
#
include
<
grpcpp
/
server_context
.
h
>
7
8
USERVER_NAMESPACE_BEGIN
9
10
namespace
ugrpc::server {
11
12
/// @brief Interface to read client's requests.
13
///
14
/// This class is not thread-safe.
15
///
16
/// If any method throws, further methods must not be called on the same stream.
17
template
<
class
Request>
18
class
Reader
{
19
public
:
20
/// @cond
21
virtual
~Reader() =
default
;
22
/// @endcond
23
24
/// @brief Await and read the next incoming message
25
/// @param request where to put the request on success
26
/// @returns `true` on success, `false` on end-of-input
27
/// @throws ugrpc::server::RpcError on an RPC error
28
[[
nodiscard
]]
virtual
bool
Read
(Request& request) = 0;
29
};
30
31
/// @brief Interface to write server's responses.
32
///
33
/// This class is not thread-safe.
34
///
35
/// If any method throws, further methods must not be called on the same stream.
36
template
<
class
Response>
37
class
Writer
{
38
public
:
39
/// @cond
40
virtual
~Writer() =
default
;
41
/// @endcond
42
43
/// @brief Write the next outgoing message
44
/// @param response the next message to write
45
/// @throws ugrpc::server::RpcError on an RPC error
46
/// @throws std::exception (internal) on error from middlewares
47
///
48
/// This method uses move-only semantics for safety:
49
/// - Middlewares may modify responses during writes, making reuse dangerous
50
/// - After the call, `response` is in moved-from state and must not be reused
51
/// - Explicit std::move ensures ownership transfer and prevents accidental reuse
52
virtual
void
Write
(Response&& response) = 0;
53
54
/// @brief Write the next outgoing message
55
/// @param response the next message to write
56
/// @param options the write options
57
/// @throws ugrpc::server::RpcError on an RPC error
58
/// @throws std::exception (internal) on error from middlewares
59
///
60
/// This method uses move-only semantics for safety:
61
/// - Middlewares may modify responses during writes, making reuse dangerous
62
/// - After the call, `response` is in moved-from state and must not be reused
63
/// - Explicit std::move ensures ownership transfer and prevents accidental reuse
64
virtual
void
Write
(Response&& response,
const
grpc::WriteOptions& options) = 0;
65
};
66
67
/// @brief Interface to both read and write messages.
68
///
69
/// If any method throws, further methods must not be called on the same stream.
70
///
71
/// This class allows the following concurrent calls:
72
///
73
/// - `Read`;
74
/// - `Write`
75
///
76
/// and there can only be one Read and one Write in flight at a time.
77
///
78
/// If any method throws, further methods must not be called on the same stream.
79
template
<
class
Request,
class
Response>
80
class
ReaderWriter
:
public
Reader
<Request>,
public
Writer
<Response> {};
81
82
}
// namespace ugrpc::server
83
84
USERVER_NAMESPACE_END
userver
ugrpc
server
stream.hpp
Generated on Fri Dec 5 2025 12:22:18 for userver by
Doxygen
1.13.2