userver: userver/ugrpc/server/stream.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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
6USERVER_NAMESPACE_BEGIN
7
8namespace ugrpc::server {
9
10/// @brief Interface to read client's requests.
11///
12/// This class is not thread-safe.
13///
14/// If any method throws, further methods must not be called on the same stream.
15template <class Request>
16class Reader {
17public:
18 /// @cond
19 virtual ~Reader() = default;
20 /// @endcond
21
22 /// @brief Await and read the next incoming message
23 /// @param request where to put the request on success
24 /// @returns `true` on success, `false` on end-of-input
25 /// @throws ugrpc::server::RpcError on an RPC error
26 [[nodiscard]] virtual bool Read(Request& request) = 0;
27};
28
29/// @brief Interface to write server's responses.
30///
31/// This class is not thread-safe.
32///
33/// If any method throws, further methods must not be called on the same stream.
34template <class Response>
35class Writer {
36public:
37 /// @cond
38 virtual ~Writer() = default;
39 /// @endcond
40
41 /// @brief Write the next outgoing message
42 /// @param response the next message to write
43 /// @throws ugrpc::server::RpcError on an RPC error
44 /// @throws std::exception (internal) on error from middlewares
45 virtual void Write(Response& response) = 0;
46
47 /// @brief Write the next outgoing message
48 /// @param response the next message to write
49 /// @throws ugrpc::server::RpcError on an RPC error
50 /// @throws std::exception (internal) on error from middlewares
51 virtual void Write(Response&& response) = 0;
52};
53
54/// @brief Interface to both read and write messages.
55///
56/// If any method throws, further methods must not be called on the same stream.
57///
58/// This class allows the following concurrent calls:
59///
60/// - `Read`;
61/// - `Write`
62///
63/// and there can only be one Read and one Write in flight at a time.
64///
65/// If any method throws, further methods must not be called on the same stream.
66template <class Request, class Response>
67class ReaderWriter : public Reader<Request>, public Writer<Response> {};
68
69} // namespace ugrpc::server
70
71USERVER_NAMESPACE_END