userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
channels.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/ugrpc/client/channels.hpp
4
/// @brief Utilities for managing gRPC connections
5
6
#
include
<
grpcpp
/
channel
.
h
>
7
#
include
<
grpcpp
/
security
/
credentials
.
h
>
8
9
#
include
<
userver
/
engine
/
deadline
.
hpp
>
10
#
include
<
userver
/
engine
/
task
/
task_processor_fwd
.
hpp
>
11
12
#
include
<
userver
/
ugrpc
/
client
/
impl
/
client_data_accessor
.
hpp
>
13
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
ugrpc::client {
17
18
namespace
impl {
19
20
[[nodiscard]]
bool
TryWaitForConnected(
21
const
ClientData& client_data,
22
engine::Deadline deadline,
23
engine::TaskProcessor& blocking_task_processor
24
);
25
26
}
// namespace impl
27
28
/// @brief Create a new gRPC channel (connection pool) for the endpoint
29
///
30
/// Channel creation is expensive, reuse channels if possible.
31
///
32
/// Each channel is fully thread-safe: it can be used across multiple threads,
33
/// possibly from multiple clients and using multiple `CompletionQueue`
34
/// instances at the same time.
35
///
36
/// @param blocking_task_processor task processor for blocking channel creation
37
/// @param channel_credentials channel credentials
38
/// @param endpoint string host:port
39
/// @returns shared pointer to the gRPC channel
40
std::shared_ptr<grpc::Channel>
MakeChannel
(
41
engine::TaskProcessor& blocking_task_processor,
42
std::shared_ptr<grpc::ChannelCredentials> channel_credentials,
43
const
std::string& endpoint
44
);
45
46
/// @brief Wait until the channel state of `client` is `READY`. If the current
47
/// state is already `READY`, returns `true` immediately. In case of multiple
48
/// underlying channels, waits for all of them.
49
/// @returns `true` if the state changed before `deadline` expired
50
/// @note The wait operation does not support task cancellations
51
template
<
typename
Client>
52
[[nodiscard]]
bool
TryWaitForConnected
(
53
Client& client,
54
engine::Deadline deadline,
55
engine::TaskProcessor& blocking_task_processor
56
) {
57
return
impl::TryWaitForConnected(
58
impl::ClientDataAccessor::GetClientData(client),
59
deadline,
60
blocking_task_processor
61
);
62
}
63
64
}
// namespace ugrpc::client
65
66
USERVER_NAMESPACE_END
userver
ugrpc
client
channels.hpp
Generated on
for userver by
Doxygen
1.17.0