aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/grpc/server/grpc_async_ctx_base.h
diff options
context:
space:
mode:
authorDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:17 +0300
commit4b11037e5a7d071c63e3c966199fe7102e6462e4 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/grpc/server/grpc_async_ctx_base.h
parent17e20fa084178ddcb16255f974dbde74fb93608b (diff)
downloadydb-4b11037e5a7d071c63e3c966199fe7102e6462e4.tar.gz
Restoring authorship annotation for Daniil Cherednik <dcherednik@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/grpc/server/grpc_async_ctx_base.h')
-rw-r--r--library/cpp/grpc/server/grpc_async_ctx_base.h122
1 files changed, 61 insertions, 61 deletions
diff --git a/library/cpp/grpc/server/grpc_async_ctx_base.h b/library/cpp/grpc/server/grpc_async_ctx_base.h
index d170e2ef34..51356d4ce5 100644
--- a/library/cpp/grpc/server/grpc_async_ctx_base.h
+++ b/library/cpp/grpc/server/grpc_async_ctx_base.h
@@ -1,48 +1,48 @@
-#pragma once
-
-#include "grpc_server.h"
-
-#include <util/generic/vector.h>
-#include <util/generic/string.h>
-#include <util/system/yassert.h>
+#pragma once
+
+#include "grpc_server.h"
+
+#include <util/generic/vector.h>
+#include <util/generic/string.h>
+#include <util/system/yassert.h>
#include <util/generic/set.h>
-
-#include <grpc++/server.h>
-#include <grpc++/server_context.h>
-
-#include <chrono>
-
+
+#include <grpc++/server.h>
+#include <grpc++/server_context.h>
+
+#include <chrono>
+
namespace NGrpc {
-
-template<typename TService>
+
+template<typename TService>
class TBaseAsyncContext: public ICancelableContext {
-public:
- TBaseAsyncContext(typename TService::TCurrentGRpcService::AsyncService* service, grpc::ServerCompletionQueue* cq)
- : Service(service)
- , CQ(cq)
- {
- }
-
- TString GetPeerName() const {
- return TString(Context.peer());
- }
-
- TInstant Deadline() const {
- // The timeout transferred in "grpc-timeout" header [1] and calculated from the deadline
+public:
+ TBaseAsyncContext(typename TService::TCurrentGRpcService::AsyncService* service, grpc::ServerCompletionQueue* cq)
+ : Service(service)
+ , CQ(cq)
+ {
+ }
+
+ TString GetPeerName() const {
+ return TString(Context.peer());
+ }
+
+ TInstant Deadline() const {
+ // The timeout transferred in "grpc-timeout" header [1] and calculated from the deadline
// right before the request is getting to be send.
// 1. https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md
//
- // After this timeout calculated back to the deadline on the server side
- // using server grpc GPR_CLOCK_MONOTONIC time (raw_deadline() method).
- // deadline() method convert this to epoch related deadline GPR_CLOCK_REALTIME
- //
-
- std::chrono::system_clock::time_point t = Context.deadline();
- if (t == std::chrono::system_clock::time_point::max()) {
- return TInstant::Max();
+ // After this timeout calculated back to the deadline on the server side
+ // using server grpc GPR_CLOCK_MONOTONIC time (raw_deadline() method).
+ // deadline() method convert this to epoch related deadline GPR_CLOCK_REALTIME
+ //
+
+ std::chrono::system_clock::time_point t = Context.deadline();
+ if (t == std::chrono::system_clock::time_point::max()) {
+ return TInstant::Max();
}
- auto us = std::chrono::time_point_cast<std::chrono::microseconds>(t);
- return TInstant::MicroSeconds(us.time_since_epoch().count());
+ auto us = std::chrono::time_point_cast<std::chrono::microseconds>(t);
+ return TInstant::MicroSeconds(us.time_since_epoch().count());
}
TSet<TStringBuf> GetPeerMetaKeys() const {
@@ -54,7 +54,7 @@ public:
}
TVector<TStringBuf> GetPeerMetaValues(TStringBuf key) const {
- const auto& clientMetadata = Context.client_metadata();
+ const auto& clientMetadata = Context.client_metadata();
const auto range = clientMetadata.equal_range(grpc::string_ref{key.data(), key.size()});
if (range.first == range.second) {
return {};
@@ -63,32 +63,32 @@ public:
TVector<TStringBuf> values;
values.reserve(std::distance(range.first, range.second));
- for (auto it = range.first; it != range.second; ++it) {
+ for (auto it = range.first; it != range.second; ++it) {
values.emplace_back(it->second.data(), it->second.size());
- }
+ }
return values;
- }
-
+ }
+
grpc_compression_level GetCompressionLevel() const {
return Context.compression_level();
}
- void Shutdown() override {
- // Shutdown may only be called after request has started successfully
- if (Context.c_call())
- Context.TryCancel();
- }
-
-protected:
- //! The means of communication with the gRPC runtime for an asynchronous
- //! server.
- typename TService::TCurrentGRpcService::AsyncService* const Service;
- //! The producer-consumer queue where for asynchronous server notifications.
- grpc::ServerCompletionQueue* const CQ;
- //! Context for the rpc, allowing to tweak aspects of it such as the use
- //! of compression, authentication, as well as to send metadata back to the
- //! client.
- grpc::ServerContext Context;
-};
-
+ void Shutdown() override {
+ // Shutdown may only be called after request has started successfully
+ if (Context.c_call())
+ Context.TryCancel();
+ }
+
+protected:
+ //! The means of communication with the gRPC runtime for an asynchronous
+ //! server.
+ typename TService::TCurrentGRpcService::AsyncService* const Service;
+ //! The producer-consumer queue where for asynchronous server notifications.
+ grpc::ServerCompletionQueue* const CQ;
+ //! Context for the rpc, allowing to tweak aspects of it such as the use
+ //! of compression, authentication, as well as to send metadata back to the
+ //! client.
+ grpc::ServerContext Context;
+};
+
} // namespace NGrpc