aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2017-09-25 12:36:30 -0700
committerGravatar Mark D. Roth <roth@google.com>2017-09-25 12:36:30 -0700
commitb4c01f9e2982d61723014f76c42fc059c554b084 (patch)
tree7ac46ab54a86744ae26317a2365e0f9fe8647812 /src/cpp
parentad9208c07e74d90dd5110324fe9cb830e6e6f68b (diff)
parent008a173a7e2ba1d5c0933aa7a77395945ba2024d (diff)
Merge remote-tracking branch 'upstream/master' into plugin_credentials_api_fix
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/client_context.cc2
-rw-r--r--src/cpp/client/generic_stub.cc33
-rw-r--r--src/cpp/server/health/default_health_check_service.cc1
-rw-r--r--src/cpp/server/server_context.cc2
-rw-r--r--src/cpp/util/byte_buffer_cc.cc31
-rw-r--r--src/cpp/util/slice_cc.cc2
6 files changed, 51 insertions, 20 deletions
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc
index 3af8bdc11a..40e95f3c05 100644
--- a/src/cpp/client/client_context.cc
+++ b/src/cpp/client/client_context.cc
@@ -96,7 +96,7 @@ void ClientContext::set_call(grpc_call* call,
void ClientContext::set_compression_algorithm(
grpc_compression_algorithm algorithm) {
- char* algorithm_name = nullptr;
+ const char* algorithm_name = nullptr;
if (!grpc_compression_algorithm_name(algorithm, &algorithm_name)) {
gpr_log(GPR_ERROR, "Name for compression algorithm '%d' unknown.",
algorithm);
diff --git a/src/cpp/client/generic_stub.cc b/src/cpp/client/generic_stub.cc
index 66b1ef0e39..693b8bea56 100644
--- a/src/cpp/client/generic_stub.cc
+++ b/src/cpp/client/generic_stub.cc
@@ -22,14 +22,39 @@
namespace grpc {
+namespace {
+std::unique_ptr<GenericClientAsyncReaderWriter> CallInternal(
+ ChannelInterface* channel, ClientContext* context,
+ const grpc::string& method, CompletionQueue* cq, bool start, void* tag) {
+ return std::unique_ptr<GenericClientAsyncReaderWriter>(
+ GenericClientAsyncReaderWriter::Create(
+ channel, cq, RpcMethod(method.c_str(), RpcMethod::BIDI_STREAMING),
+ context, start, tag));
+}
+
+} // namespace
+
// begin a call to a named method
std::unique_ptr<GenericClientAsyncReaderWriter> GenericStub::Call(
ClientContext* context, const grpc::string& method, CompletionQueue* cq,
void* tag) {
- return std::unique_ptr<GenericClientAsyncReaderWriter>(
- GenericClientAsyncReaderWriter::Create(
- channel_.get(), cq,
- RpcMethod(method.c_str(), RpcMethod::BIDI_STREAMING), context, tag));
+ return CallInternal(channel_.get(), context, method, cq, true, tag);
+}
+
+// setup a call to a named method
+std::unique_ptr<GenericClientAsyncReaderWriter> GenericStub::PrepareCall(
+ ClientContext* context, const grpc::string& method, CompletionQueue* cq) {
+ return CallInternal(channel_.get(), context, method, cq, false, nullptr);
+}
+
+// setup a unary call to a named method
+std::unique_ptr<GenericClientAsyncResponseReader> GenericStub::PrepareUnaryCall(
+ ClientContext* context, const grpc::string& method,
+ const ByteBuffer& request, CompletionQueue* cq) {
+ return std::unique_ptr<GenericClientAsyncResponseReader>(
+ GenericClientAsyncResponseReader::Create(
+ channel_.get(), cq, RpcMethod(method.c_str(), RpcMethod::NORMAL_RPC),
+ context, request, false));
}
} // namespace grpc
diff --git a/src/cpp/server/health/default_health_check_service.cc b/src/cpp/server/health/default_health_check_service.cc
index 815b607032..d2cba6d662 100644
--- a/src/cpp/server/health/default_health_check_service.cc
+++ b/src/cpp/server/health/default_health_check_service.cc
@@ -20,6 +20,7 @@
#include <mutex>
#include <grpc++/impl/codegen/method_handler_impl.h>
+#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc
index 4913682f1d..d7876a000b 100644
--- a/src/cpp/server/server_context.cc
+++ b/src/cpp/server/server_context.cc
@@ -190,7 +190,7 @@ bool ServerContext::IsCancelled() const {
void ServerContext::set_compression_algorithm(
grpc_compression_algorithm algorithm) {
- char* algorithm_name = NULL;
+ const char* algorithm_name = NULL;
if (!grpc_compression_algorithm_name(algorithm, &algorithm_name)) {
gpr_log(GPR_ERROR, "Name for compression algorithm '%d' unknown.",
algorithm);
diff --git a/src/cpp/util/byte_buffer_cc.cc b/src/cpp/util/byte_buffer_cc.cc
index b1ff25252a..180c813762 100644
--- a/src/cpp/util/byte_buffer_cc.cc
+++ b/src/cpp/util/byte_buffer_cc.cc
@@ -16,11 +16,15 @@
*
*/
+#include <grpc++/impl/grpc_library.h>
#include <grpc++/support/byte_buffer.h>
+#include <grpc/byte_buffer.h>
#include <grpc/byte_buffer_reader.h>
namespace grpc {
+static internal::GrpcLibraryInitializer g_gli_initializer;
+
ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) {
// The following assertions check that the representation of a grpc::Slice is
// identical to that of a grpc_slice: it has a grpc_slice field, and nothing
@@ -29,6 +33,16 @@ ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) {
"Slice must have same representation as grpc_slice");
static_assert(sizeof(Slice) == sizeof(grpc_slice),
"Slice must have same representation as grpc_slice");
+ // The following assertions check that the representation of a ByteBuffer is
+ // identical to grpc_byte_buffer*: it has a grpc_byte_buffer* field,
+ // and nothing else.
+ static_assert(std::is_same<decltype(buffer_), grpc_byte_buffer*>::value,
+ "ByteBuffer must have same representation as "
+ "grpc_byte_buffer*");
+ static_assert(sizeof(ByteBuffer) == sizeof(grpc_byte_buffer*),
+ "ByteBuffer must have same representation as "
+ "grpc_byte_buffer*");
+ g_gli_initializer.summon(); // Make sure that initializer linked in
// The const_cast is legal if grpc_raw_byte_buffer_create() does no more
// than its advertised side effect of increasing the reference count of the
// slices it processes, and such an increase does not affect the semantics
@@ -37,19 +51,6 @@ ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) {
reinterpret_cast<grpc_slice*>(const_cast<Slice*>(slices)), nslices);
}
-ByteBuffer::~ByteBuffer() {
- if (buffer_) {
- grpc_byte_buffer_destroy(buffer_);
- }
-}
-
-void ByteBuffer::Clear() {
- if (buffer_) {
- grpc_byte_buffer_destroy(buffer_);
- buffer_ = nullptr;
- }
-}
-
Status ByteBuffer::Dump(std::vector<Slice>* slices) const {
slices->clear();
if (!buffer_) {
@@ -80,7 +81,9 @@ ByteBuffer::ByteBuffer(const ByteBuffer& buf)
: buffer_(grpc_byte_buffer_copy(buf.buffer_)) {}
ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) {
- Clear(); // first remove existing data
+ if (this != &buf) {
+ Clear(); // first remove existing data
+ }
if (buf.buffer_) {
buffer_ = grpc_byte_buffer_copy(buf.buffer_); // then copy
}
diff --git a/src/cpp/util/slice_cc.cc b/src/cpp/util/slice_cc.cc
index 486d0cdf0e..3ae17e8052 100644
--- a/src/cpp/util/slice_cc.cc
+++ b/src/cpp/util/slice_cc.cc
@@ -50,4 +50,6 @@ Slice::Slice(void* buf, size_t len, void (*destroy)(void*), void* user_data)
Slice::Slice(void* buf, size_t len, void (*destroy)(void*, size_t))
: slice_(grpc_slice_new_with_len(buf, len, destroy)) {}
+grpc_slice Slice::c_slice() const { return grpc_slice_ref(slice_); }
+
} // namespace grpc