diff options
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/client/channel.cc | 7 | ||||
-rw-r--r-- | src/cpp/client/channel.h | 4 | ||||
-rw-r--r-- | src/cpp/client/client_context.cc | 15 | ||||
-rw-r--r-- | src/cpp/client/secure_credentials.cc | 12 | ||||
-rw-r--r-- | src/cpp/common/completion_queue.cc | 12 | ||||
-rw-r--r-- | src/cpp/server/server.cc | 13 | ||||
-rw-r--r-- | src/cpp/server/server_builder.cc | 3 | ||||
-rw-r--r-- | src/cpp/server/server_context.cc | 8 | ||||
-rw-r--r-- | src/cpp/util/time.cc | 7 | ||||
-rw-r--r-- | src/cpp/util/time.h | 51 |
10 files changed, 37 insertions, 95 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 478f223322..c541ddfb48 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -33,7 +33,6 @@ #include "src/cpp/client/channel.h" -#include <chrono> #include <memory> #include <grpc/grpc.h> @@ -65,14 +64,14 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, method.channel_tag() ? grpc_channel_create_registered_call(c_channel_, cq->cq(), method.channel_tag(), - context->RawDeadline()) + context->raw_deadline()) : grpc_channel_create_call(c_channel_, cq->cq(), method.name(), context->authority().empty() ? target_.c_str() : context->authority().c_str(), - context->RawDeadline()); + context->raw_deadline()); GRPC_TIMER_MARK(CALL_CREATED, c_call); - context->set_call(c_call); + context->set_call(c_call, shared_from_this()); return Call(c_call, this, cq); } diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index aaf4dbe10d..cd239247c8 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -38,6 +38,7 @@ #include <grpc++/channel_interface.h> #include <grpc++/config.h> +#include <grpc++/impl/grpc_library.h> struct grpc_channel; @@ -49,7 +50,8 @@ class CompletionQueue; class Credentials; class StreamContextInterface; -class Channel GRPC_FINAL : public ChannelInterface { +class Channel GRPC_FINAL : public GrpcLibrary, + public ChannelInterface { public: Channel(const grpc::string& target, grpc_channel* c_channel); ~Channel() GRPC_OVERRIDE; 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 <grpc++/client_context.h> #include <grpc/grpc.h> -#include "src/cpp/util/time.h" - -using std::chrono::system_clock; +#include <grpc++/time.h> 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 0a73b2c0f6..48bf7430b2 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -81,27 +81,27 @@ std::unique_ptr<Credentials> ComputeEngineCredentials() { // Builds service account credentials. std::unique_ptr<Credentials> ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, - std::chrono::seconds token_lifetime) { - if (token_lifetime.count() <= 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.count()); + 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<Credentials> JWTCredentials( - const grpc::string& json_key, std::chrono::seconds token_lifetime) { - if (token_lifetime.count() <= 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.count()); + gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime_seconds); 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..07122db4a5 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -36,7 +36,7 @@ #include <grpc/grpc.h> #include <grpc/support/log.h> -#include "src/cpp/util/time.h" +#include <grpc++/time.h> 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<grpc_event, EventDeleter> ev; @@ -92,7 +85,8 @@ bool CompletionQueue::Pluck(CompletionQueueTag* tag) { void* ignored = tag; GPR_ASSERT(tag->FinalizeResult(&ignored, &ok)); GPR_ASSERT(ignored == tag); - return ok; + // Ignore mutations by FinalizeResult: Pluck returns the C API status + return ev->data.op_complete == GRPC_OP_OK; } void CompletionQueue::TryPluck(CompletionQueueTag* tag) { diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index b3cd1fdd74..4694a3a7ff 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -45,10 +45,10 @@ #include <grpc++/server_context.h> #include <grpc++/server_credentials.h> #include <grpc++/thread_pool_interface.h> +#include <grpc++/time.h> #include "src/core/profiling/timers.h" #include "src/cpp/proto/proto_utils.h" -#include "src/cpp/util/time.h" namespace grpc { @@ -180,6 +180,7 @@ Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned) : started_(false), shutdown_(false), num_running_cb_(0), + sync_methods_(new std::list<SyncRequest>), server_(grpc_server_create(cq_.cq(), nullptr)), thread_pool_(thread_pool), thread_pool_owned_(thread_pool_owned) {} @@ -196,6 +197,7 @@ Server::~Server() { if (thread_pool_owned_) { delete thread_pool_; } + delete sync_methods_; } bool Server::RegisterService(RpcService* service) { @@ -208,7 +210,8 @@ bool Server::RegisterService(RpcService* service) { method->name()); return false; } - sync_methods_.emplace_back(method, tag); + SyncRequest request(method, tag); + sync_methods_->emplace_back(request); } return true; } @@ -250,8 +253,8 @@ bool Server::Start() { grpc_server_start(server_); // Start processing rpcs. - if (!sync_methods_.empty()) { - for (auto m = sync_methods_.begin(); m != sync_methods_.end(); m++) { + if (!sync_methods_->empty()) { + for (auto m = sync_methods_->begin(); m != sync_methods_->end(); m++) { m->Request(server_); } @@ -353,7 +356,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_builder.cc b/src/cpp/server/server_builder.cc index c5e115f396..81cb0e6724 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -66,7 +66,8 @@ void ServerBuilder::RegisterAsyncGenericService(AsyncGenericService* service) { void ServerBuilder::AddListeningPort(const grpc::string& addr, std::shared_ptr<ServerCredentials> creds, int* selected_port) { - ports_.push_back(Port{addr, creds, selected_port}); + Port port = {addr, creds, selected_port}; + ports_.push_back(port); } void ServerBuilder::SetThreadPool(ThreadPoolInterface* thread_pool) { 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 <grpc++/server_context.h> -#include <grpc++/impl/call.h> -#include <grpc++/impl/sync.h> #include <grpc/grpc.h> #include <grpc/support/log.h> -#include "src/cpp/util/time.h" +#include <grpc++/impl/call.h> +#include <grpc++/impl/sync.h> +#include <grpc++/time.h> 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 <grpc++/config.h> + +#ifndef GRPC_CXX0X_NO_CHRONO #include <grpc/support/time.h> +#include <grpc++/time.h> 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 <chrono> - -#include <grpc/support/time.h> - -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 |