userver: userver/ugrpc/server/server.hpp Source File
Loading...
Searching...
No Matches
server.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <functional>
7#include <memory>
8#include <unordered_map>
9
10#include <grpcpp/completion_queue.h>
11#include <grpcpp/server_builder.h>
12
18#include <userver/utils/impl/internal_tag_fwd.hpp>
22
23#include <userver/ugrpc/impl/statistics.hpp>
26
27USERVER_NAMESPACE_BEGIN
28
29namespace ugrpc::impl {
30class CompletionQueuePoolBase;
31} // namespace ugrpc::impl
32
33namespace ugrpc::server {
34
36
37struct TlsConfig {
38 // Certificate Authority, for client auth
39 std::optional<std::string> ca;
40
41 // Server certificate private key
42 std::optional<std::string> key;
43
44 // Server certificate
45 std::optional<std::string> cert;
46};
47
49struct EventEngineConfig final {
57 bool enabled{false};
58
63 engine::TaskProcessor* task_processor{nullptr};
64};
65
67struct ServerConfig final {
71 std::optional<int> port{0};
72
75 std::optional<std::string> unix_socket_path{std::nullopt};
76
78 bool use_callback_api{false};
79
82 std::size_t completion_queue_num{2};
83
86 std::unordered_map<std::string, std::string> channel_args{};
87
91
93 bool enable_channelz{false};
94
97
100
103};
104
109class Server final : public USERVER_NAMESPACE::server::congestion_control::RequestsSource {
110public:
111 using SetupHook = utils::function_ref<void(grpc::ServerBuilder&)>;
112
117 explicit Server(
118 utils::ResourceScopeStorage& scope_storage,
119 ServerConfig&& config,
120 utils::statistics::Storage& statistics_storage
121 );
122
123 Server(Server&&) = delete;
124 Server& operator=(Server&&) = delete;
125 ~Server() override;
126
130 void AddService(ServiceBase& service, ServiceConfig&& config);
131
134
136 std::vector<std::string_view> GetServiceNames() const;
137
140 void WithServerBuilder(SetupHook setup);
141
144 void Start();
145
148 int GetPort() const noexcept;
149
153 void Stop() noexcept;
154
159 void StopServing(std::optional<engine::Deadline> serving_shutdown_deadline = std::nullopt) noexcept;
160
162 // For internal use only.
163 std::uint64_t GetTotalRequests() const override;
164
165 // For internal use only.
166 ugrpc::impl::CompletionQueuePoolBase* GetCompletionQueues(utils::impl::InternalTag);
168
169private:
170 class Impl;
171 std::unique_ptr<Impl> impl_;
172};
173
174} // namespace ugrpc::server
175
176USERVER_NAMESPACE_END