From ffc8a6b4318fdf14516b4b0a816e118131c2f209 Mon Sep 17 00:00:00 2001 From: yang-g Date: Mon, 10 Aug 2015 12:26:39 -0700 Subject: move auth property iterator declaration into auth_context.h --- include/grpc++/auth_context.h | 32 +++++++++++++- include/grpc++/auth_property_iterator.h | 77 --------------------------------- 2 files changed, 31 insertions(+), 78 deletions(-) delete mode 100644 include/grpc++/auth_property_iterator.h (limited to 'include/grpc++') diff --git a/include/grpc++/auth_context.h b/include/grpc++/auth_context.h index c42105b927..f8ea8ad6f4 100644 --- a/include/grpc++/auth_context.h +++ b/include/grpc++/auth_context.h @@ -34,12 +34,42 @@ #ifndef GRPCXX_AUTH_CONTEXT_H #define GRPCXX_AUTH_CONTEXT_H +#include #include -#include #include +struct grpc_auth_context; +struct grpc_auth_property; +struct grpc_auth_property_iterator; + namespace grpc { +class SecureAuthContext; + +typedef std::pair AuthProperty; + +class AuthPropertyIterator + : public std::iterator { + public: + ~AuthPropertyIterator(); + AuthPropertyIterator& operator++(); + AuthPropertyIterator operator++(int); + bool operator==(const AuthPropertyIterator& rhs) const; + bool operator!=(const AuthPropertyIterator& rhs) const; + const AuthProperty operator*(); + + protected: + AuthPropertyIterator(); + AuthPropertyIterator(const grpc_auth_property* property, + const grpc_auth_property_iterator* iter); + private: + friend class SecureAuthContext; + const grpc_auth_property* property_; + // The following items form a grpc_auth_property_iterator. + const grpc_auth_context* ctx_; + size_t index_; + const char* name_; +}; class AuthContext { public: diff --git a/include/grpc++/auth_property_iterator.h b/include/grpc++/auth_property_iterator.h deleted file mode 100644 index c7870c46be..0000000000 --- a/include/grpc++/auth_property_iterator.h +++ /dev/null @@ -1,77 +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 GRPCXX_AUTH_PROPERTY_ITERATOR_H -#define GRPCXX_AUTH_PROPERTY_ITERATOR_H - -#include -#include - -#include - -struct grpc_auth_context; -struct grpc_auth_property; -struct grpc_auth_property_iterator; - -namespace grpc { -class SecureAuthContext; - -typedef std::pair AuthProperty; - -class AuthPropertyIterator - : public std::iterator { - public: - ~AuthPropertyIterator(); - AuthPropertyIterator& operator++(); - AuthPropertyIterator operator++(int); - bool operator==(const AuthPropertyIterator& rhs) const; - bool operator!=(const AuthPropertyIterator& rhs) const; - const AuthProperty operator*(); - - protected: - AuthPropertyIterator(); - AuthPropertyIterator(const grpc_auth_property* property, - const grpc_auth_property_iterator* iter); - private: - friend class SecureAuthContext; - const grpc_auth_property* property_; - // The following items form a grpc_auth_property_iterator. - const grpc_auth_context* ctx_; - size_t index_; - const char* name_; -}; - -} // namespace grpc - - #endif // GRPCXX_AUTH_PROPERTY_ITERATOR_H - -- cgit v1.2.3 From 0c034a01d12753a06a3dbbe202430ff0485ab978 Mon Sep 17 00:00:00 2001 From: yang-g Date: Tue, 11 Aug 2015 11:46:32 -0700 Subject: client code clean up --- include/grpc++/client_context.h | 4 ---- src/cpp/client/channel.cc | 32 +++++++++++++++++++------------- src/cpp/client/client_context.cc | 9 --------- 3 files changed, 19 insertions(+), 26 deletions(-) (limited to 'include/grpc++') diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 34945f3282..d7fafac9b3 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -218,15 +218,11 @@ class ClientContext { void set_call(grpc_call* call, const std::shared_ptr& channel); - grpc_completion_queue* cq() { return cq_; } - void set_cq(grpc_completion_queue* cq) { cq_ = cq; } - grpc::string authority() { return authority_; } bool initial_metadata_received_; std::shared_ptr channel_; grpc_call* call_; - grpc_completion_queue* cq_; gpr_timespec deadline_; grpc::string authority_; std::shared_ptr creds_; diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index af7366eb01..93536ae367 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -61,19 +61,25 @@ Channel::~Channel() { grpc_channel_destroy(c_channel_); } Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq) { - const char* host_str = host_.empty() ? NULL : host_.c_str(); - auto c_call = method.channel_tag() && context->authority().empty() - ? grpc_channel_create_registered_call( - c_channel_, context->propagate_from_call_, - context->propagation_options_.c_bitmask(), cq->cq(), - method.channel_tag(), context->raw_deadline()) - : grpc_channel_create_call( - c_channel_, context->propagate_from_call_, - context->propagation_options_.c_bitmask(), cq->cq(), - method.name(), context->authority().empty() - ? host_str - : context->authority().c_str(), - context->raw_deadline()); + bool registered = method.channel_tag() && context->authority().empty(); + grpc_call* c_call = NULL; + if (registered) { + c_call = grpc_channel_create_registered_call( + c_channel_, context->propagate_from_call_, + context->propagation_options_.c_bitmask(), cq->cq(), + method.channel_tag(), context->raw_deadline()); + } else { + const char* host_str = NULL; + if (!context->authority().empty()) { + host_str = context->authority().c_str(); + } else if (!host_.empty()) { + host_str = host_.c_str(); + } + c_call = grpc_channel_create_call(c_channel_, context->propagate_from_call_, + context->propagation_options_.c_bitmask(), + cq->cq(), method.name(), host_str, + context->raw_deadline()); + } grpc_census_call_set_context(c_call, context->census_context()); GRPC_TIMER_MARK(GRPC_PTAG_CPP_CALL_CREATED, c_call); context->set_call(c_call, shared_from_this()); diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index 1ed2d38961..dd86e7b108 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -48,7 +48,6 @@ namespace grpc { ClientContext::ClientContext() : initial_metadata_received_(false), call_(nullptr), - cq_(nullptr), deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)), propagate_from_call_(nullptr) {} @@ -56,14 +55,6 @@ ClientContext::~ClientContext() { if (call_) { grpc_call_destroy(call_); } - if (cq_) { - // Drain cq_. - grpc_completion_queue_shutdown(cq_); - while (grpc_completion_queue_next(cq_, gpr_inf_future(GPR_CLOCK_REALTIME)) - .type != GRPC_QUEUE_SHUTDOWN) - ; - grpc_completion_queue_destroy(cq_); - } } std::unique_ptr ClientContext::FromServerContext( -- cgit v1.2.3