aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/client_context.cc3
-rw-r--r--src/cpp/server/server.cc19
-rw-r--r--src/cpp/util/byte_buffer.cc8
3 files changed, 17 insertions, 13 deletions
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc
index 2aa532808c..710d7cb5c2 100644
--- a/src/cpp/client/client_context.cc
+++ b/src/cpp/client/client_context.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,6 +48,7 @@ namespace grpc {
class DefaultGlobalClientCallbacks GRPC_FINAL
: public ClientContext::GlobalCallbacks {
public:
+ ~DefaultGlobalClientCallbacks() GRPC_OVERRIDE {}
void DefaultConstructor(ClientContext* context) GRPC_OVERRIDE {}
void Destructor(ClientContext* context) GRPC_OVERRIDE {}
};
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 878775bbee..3bf9f3fa0f 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,17 +53,17 @@ namespace grpc {
class DefaultGlobalCallbacks GRPC_FINAL : public Server::GlobalCallbacks {
public:
+ ~DefaultGlobalCallbacks() GRPC_OVERRIDE {}
void PreSynchronousRequest(ServerContext* context) GRPC_OVERRIDE {}
void PostSynchronousRequest(ServerContext* context) GRPC_OVERRIDE {}
};
-static Server::GlobalCallbacks* g_callbacks = nullptr;
+static std::shared_ptr<Server::GlobalCallbacks> g_callbacks = nullptr;
static gpr_once g_once_init_callbacks = GPR_ONCE_INIT;
static void InitGlobalCallbacks() {
if (g_callbacks == nullptr) {
- static DefaultGlobalCallbacks default_global_callbacks;
- g_callbacks = &default_global_callbacks;
+ g_callbacks.reset(new DefaultGlobalCallbacks());
}
}
@@ -234,12 +234,12 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
}
}
- void Run() {
+ void Run(std::shared_ptr<GlobalCallbacks> global_callbacks) {
ctx_.BeginCompletionOp(&call_);
- g_callbacks->PreSynchronousRequest(&ctx_);
+ global_callbacks->PreSynchronousRequest(&ctx_);
method_->handler()->RunHandler(MethodHandler::HandlerParameter(
&call_, &ctx_, request_payload_, call_.max_message_size()));
- g_callbacks->PostSynchronousRequest(&ctx_);
+ global_callbacks->PostSynchronousRequest(&ctx_);
request_payload_ = nullptr;
void* ignored_tag;
bool ignored_ok;
@@ -287,6 +287,7 @@ Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
thread_pool_(thread_pool),
thread_pool_owned_(thread_pool_owned) {
gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks);
+ global_callbacks_ = g_callbacks;
grpc_server_register_completion_queue(server_, cq_.cq(), nullptr);
}
@@ -311,7 +312,7 @@ Server::~Server() {
void Server::SetGlobalCallbacks(GlobalCallbacks* callbacks) {
GPR_ASSERT(g_callbacks == nullptr);
GPR_ASSERT(callbacks != nullptr);
- g_callbacks = callbacks;
+ g_callbacks.reset(callbacks);
}
bool Server::RegisterService(const grpc::string* host, RpcService* service) {
@@ -569,7 +570,7 @@ void Server::RunRpc() {
}
}
GPR_TIMER_SCOPE("cd.Run()", 0);
- cd.Run();
+ cd.Run(global_callbacks_);
}
}
diff --git a/src/cpp/util/byte_buffer.cc b/src/cpp/util/byte_buffer.cc
index 2952f94b24..3a2318d1a6 100644
--- a/src/cpp/util/byte_buffer.cc
+++ b/src/cpp/util/byte_buffer.cc
@@ -31,8 +31,8 @@
*
*/
-#include <grpc/byte_buffer_reader.h>
#include <grpc++/support/byte_buffer.h>
+#include <grpc/byte_buffer_reader.h>
namespace grpc {
@@ -84,8 +84,10 @@ ByteBuffer::ByteBuffer(const ByteBuffer& buf)
: buffer_(grpc_byte_buffer_copy(buf.buffer_)) {}
ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) {
- Clear(); // first remove existing data
- buffer_ = grpc_byte_buffer_copy(buf.buffer_); // then copy
+ Clear(); // first remove existing data
+ if (buf.buffer_) {
+ buffer_ = grpc_byte_buffer_copy(buf.buffer_); // then copy
+ }
return *this;
}