From 89219162dd613b58da8f3cd418f4825a5d566da5 Mon Sep 17 00:00:00 2001 From: Nicolas Noble Date: Tue, 7 Apr 2015 18:01:18 -0700 Subject: Refactoring std::chrono out. --- src/cpp/client/channel.cc | 3 +-- src/cpp/client/client_context.cc | 15 ++--------- src/cpp/client/secure_credentials.cc | 12 ++++----- src/cpp/common/completion_queue.cc | 9 +------ src/cpp/server/server.cc | 4 +-- src/cpp/server/server_context.cc | 8 +++--- src/cpp/util/time.cc | 7 ++++- src/cpp/util/time.h | 51 ------------------------------------ 8 files changed, 22 insertions(+), 87 deletions(-) delete mode 100644 src/cpp/util/time.h (limited to 'src/cpp') diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 5380d3a232..aaad042026 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -33,7 +33,6 @@ #include "src/cpp/client/channel.h" -#include #include #include @@ -64,7 +63,7 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, context->authority().empty() ? target_.c_str() : context->authority().c_str(), - context->RawDeadline()); + context->raw_deadline()); context->set_call(c_call); return Call(c_call, this, cq); } diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index de9f8c7201..70c9cb4c3b 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -34,9 +34,7 @@ #include #include -#include "src/cpp/util/time.h" - -using std::chrono::system_clock; +#include namespace grpc { @@ -44,7 +42,7 @@ ClientContext::ClientContext() : initial_metadata_received_(false), call_(nullptr), cq_(nullptr), - absolute_deadline_(gpr_inf_future) {} + deadline_(gpr_inf_future) {} ClientContext::~ClientContext() { if (call_) { @@ -64,15 +62,6 @@ ClientContext::~ClientContext() { } } -void ClientContext::set_absolute_deadline( - const system_clock::time_point& deadline) { - Timepoint2Timespec(deadline, &absolute_deadline_); -} - -system_clock::time_point ClientContext::absolute_deadline() { - return Timespec2Timepoint(absolute_deadline_); -} - void ClientContext::AddMetadata(const grpc::string& meta_key, const grpc::string& meta_value) { send_initial_metadata_.insert(std::make_pair(meta_key, meta_value)); diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index d6f9acc675..85785ed275 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -96,27 +96,27 @@ std::unique_ptr ComputeEngineCredentials() { // Builds service account credentials. std::unique_ptr ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, - std::chrono::seconds token_lifetime) { - if (token_lifetime.count() <= 0) { + long token_lifetime) { + if (token_lifetime <= 0) { gpr_log(GPR_ERROR, "Trying to create ServiceAccountCredentials " "with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime); return WrapCredentials(grpc_service_account_credentials_create( json_key.c_str(), scope.c_str(), lifetime)); } // Builds JWT credentials. std::unique_ptr JWTCredentials( - const grpc::string& json_key, std::chrono::seconds token_lifetime) { - if (token_lifetime.count() <= 0) { + const grpc::string& json_key, long token_lifetime) { + if (token_lifetime <= 0) { gpr_log(GPR_ERROR, "Trying to create JWTCredentials with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime); return WrapCredentials( grpc_jwt_credentials_create(json_key.c_str(), lifetime)); } diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index cea2d24831..3c37e91e1f 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -36,7 +36,7 @@ #include #include -#include "src/cpp/util/time.h" +#include namespace grpc { @@ -77,13 +77,6 @@ CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal( } } -CompletionQueue::NextStatus CompletionQueue::AsyncNext( - void** tag, bool* ok, std::chrono::system_clock::time_point deadline) { - gpr_timespec gpr_deadline; - Timepoint2Timespec(deadline, &gpr_deadline); - return AsyncNextInternal(tag, ok, gpr_deadline); -} - bool CompletionQueue::Pluck(CompletionQueueTag* tag) { std::unique_ptr ev; diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 046133c5eb..2833f78a75 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -45,9 +45,9 @@ #include #include #include +#include #include "src/cpp/proto/proto_utils.h" -#include "src/cpp/util/time.h" namespace grpc { @@ -348,7 +348,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag { ServerContext* ctx = ctx_ ? ctx_ : generic_ctx_; GPR_ASSERT(ctx); if (*status) { - ctx->deadline_ = Timespec2Timepoint(call_details_.deadline); + ctx->deadline_ = call_details_.deadline; for (size_t i = 0; i < array_.count; i++) { ctx->client_metadata_.insert(std::make_pair( grpc::string(array_.metadata[i].key), diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index ffd6d30d5d..6b5e41d0a8 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -33,11 +33,11 @@ #include -#include -#include #include #include -#include "src/cpp/util/time.h" +#include +#include +#include namespace grpc { @@ -99,7 +99,7 @@ ServerContext::ServerContext() ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, size_t metadata_count) : completion_op_(nullptr), - deadline_(Timespec2Timepoint(deadline)), + deadline_(deadline), call_(nullptr), cq_(nullptr), sent_initial_metadata_(false) { diff --git a/src/cpp/util/time.cc b/src/cpp/util/time.cc index 059ea72abf..1fef2a56de 100644 --- a/src/cpp/util/time.cc +++ b/src/cpp/util/time.cc @@ -31,9 +31,12 @@ * */ -#include "src/cpp/util/time.h" +#include + +#ifndef GRPC_CXX0X_NO_CHRONO #include +#include using std::chrono::duration_cast; using std::chrono::nanoseconds; @@ -68,3 +71,5 @@ system_clock::time_point Timespec2Timepoint(gpr_timespec t) { } } // namespace grpc + +#endif // !GRPC_CXX0X_NO_CHRONO diff --git a/src/cpp/util/time.h b/src/cpp/util/time.h deleted file mode 100644 index 8b7fcf55f7..0000000000 --- a/src/cpp/util/time.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_INTERNAL_CPP_UTIL_TIME_H -#define GRPC_INTERNAL_CPP_UTIL_TIME_H - -#include - -#include - -namespace grpc { - -// from and to should be absolute time. -void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, - gpr_timespec* to); - -std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); - -} // namespace grpc - -#endif // GRPC_INTERNAL_CPP_UTIL_TIME_H -- cgit v1.2.3 From e24dde5736ea833b95765f8ddefb737538dec223 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 24 Apr 2015 00:43:09 +0200 Subject: Adressing comments. --- include/grpc++/time.h | 6 +++--- src/cpp/client/secure_credentials.cc | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/cpp') diff --git a/include/grpc++/time.h b/include/grpc++/time.h index 1fc4ad799c..ffcba4e35a 100644 --- a/include/grpc++/time.h +++ b/include/grpc++/time.h @@ -40,13 +40,13 @@ namespace grpc { /* If you are trying to use CompletionQueue::AsyncNext with a time class that isn't either gpr_timespec or std::chrono::system_clock::time_point, you - will most likely be looking at that comment as your compiler will have - fired an error below. In order to fix that issue, you have two potential + will most likely be looking at this comment as your compiler will have + fired an error below. In order to fix this issue, you have two potential solutions: 1. Use gpr_timespec or std::chrono::system_clock::time_point instead 2. Specialize the TimePoint class with whichever time class that you - want to use here. See below for two examples of how to do that. + want to use here. See below for two examples of how to do this. */ template diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 9e83ac8dcd..48bf7430b2 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -81,27 +81,27 @@ std::unique_ptr ComputeEngineCredentials() { // Builds service account credentials. std::unique_ptr ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, - long token_lifetime) { - if (token_lifetime <= 0) { + long token_lifetime_seconds) { + if (token_lifetime_seconds <= 0) { gpr_log(GPR_ERROR, "Trying to create ServiceAccountCredentials " "with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime); + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds); return WrapCredentials(grpc_service_account_credentials_create( json_key.c_str(), scope.c_str(), lifetime)); } // Builds JWT credentials. std::unique_ptr JWTCredentials( - const grpc::string& json_key, long token_lifetime) { - if (token_lifetime <= 0) { + const grpc::string& json_key, long token_lifetime_seconds) { + if (token_lifetime_seconds <= 0) { gpr_log(GPR_ERROR, "Trying to create JWTCredentials with non-positive lifetime"); return WrapCredentials(nullptr); } - gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime); + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds); return WrapCredentials( grpc_jwt_credentials_create(json_key.c_str(), lifetime)); } -- cgit v1.2.3