Make it possible to compile with gcc4.6
diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h
index 06f5a8f..e3edcf7 100644
--- a/src/cpp/client/channel.h
+++ b/src/cpp/client/channel.h
@@ -49,17 +49,17 @@
class Credentials;
class StreamContextInterface;
-class Channel final : public ChannelInterface {
+class Channel GRPC_FINAL : public ChannelInterface {
public:
Channel(const grpc::string &target, const ChannelArguments &args);
Channel(const grpc::string &target, const std::unique_ptr<Credentials> &creds,
const ChannelArguments &args);
- ~Channel() override;
+ ~Channel() GRPC_OVERRIDE;
virtual Call CreateCall(const RpcMethod &method, ClientContext *context,
- CompletionQueue *cq) override;
- virtual void PerformOpsOnCall(CallOpBuffer *ops, Call *call) override;
+ CompletionQueue *cq) GRPC_OVERRIDE;
+ virtual void PerformOpsOnCall(CallOpBuffer *ops, Call *call) GRPC_OVERRIDE;
private:
const grpc::string target_;
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc
index 80cbdd9..9f99f7b 100644
--- a/src/cpp/client/client_context.cc
+++ b/src/cpp/client/client_context.cc
@@ -41,7 +41,10 @@
namespace grpc {
ClientContext::ClientContext()
- : call_(nullptr), cq_(nullptr), absolute_deadline_(gpr_inf_future) {}
+ : initial_metadata_received_(false),
+ call_(nullptr),
+ cq_(nullptr),
+ absolute_deadline_(gpr_inf_future) {}
ClientContext::~ClientContext() {
if (call_) {
diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc
index e6a20a2..f3a6911 100644
--- a/src/cpp/common/call.cc
+++ b/src/cpp/common/call.cc
@@ -41,6 +41,30 @@
namespace grpc {
+CallOpBuffer::CallOpBuffer()
+ : return_tag_(this),
+ send_initial_metadata_(false),
+ initial_metadata_count_(0),
+ initial_metadata_(nullptr),
+ recv_initial_metadata_(nullptr),
+ recv_initial_metadata_arr_{0, 0, nullptr},
+ send_message_(nullptr),
+ send_message_buf_(nullptr),
+ recv_message_(nullptr),
+ recv_message_buf_(nullptr),
+ client_send_close_(false),
+ recv_trailing_metadata_(nullptr),
+ recv_status_(nullptr),
+ recv_trailing_metadata_arr_{0, 0, nullptr},
+ status_code_(GRPC_STATUS_OK),
+ status_details_(nullptr),
+ status_details_capacity_(0),
+ send_status_(nullptr),
+ trailing_metadata_count_(0),
+ trailing_metadata_(nullptr),
+ cancelled_buf_(0),
+ recv_closed_(nullptr) {}
+
void CallOpBuffer::Reset(void* next_return_tag) {
return_tag_ = next_return_tag;
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 178fa1a..97bf0f1 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -49,11 +49,12 @@
namespace grpc {
-class Server::SyncRequest final : public CompletionQueueTag {
+class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
public:
SyncRequest(RpcServiceMethod* method, void* tag)
: method_(method),
tag_(tag),
+ in_flight_(false),
has_request_payload_(method->method_type() == RpcMethod::NORMAL_RPC ||
method->method_type() ==
RpcMethod::SERVER_STREAMING),
@@ -85,14 +86,14 @@
this));
}
- bool FinalizeResult(void** tag, bool* status) override {
+ bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE {
if (!*status) {
grpc_completion_queue_destroy(cq_);
}
return true;
}
- class CallData final {
+ class CallData GRPC_FINAL {
public:
explicit CallData(Server* server, SyncRequest* mrd)
: cq_(mrd->cq_),
@@ -159,7 +160,7 @@
private:
RpcServiceMethod* const method_;
void* const tag_;
- bool in_flight_ = false;
+ bool in_flight_;
const bool has_request_payload_;
const bool has_response_payload_;
grpc_call* call_;
@@ -294,7 +295,7 @@
grpc_call_start_batch(call->call(), ops, nops, buf));
}
-class Server::AsyncRequest final : public CompletionQueueTag {
+class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
public:
AsyncRequest(Server* server, void* registered_method, ServerContext* ctx,
::google::protobuf::Message* request,
@@ -305,7 +306,9 @@
stream_(stream),
cq_(cq),
ctx_(ctx),
- server_(server) {
+ server_(server),
+ call_(nullptr),
+ payload_(nullptr) {
memset(&array_, 0, sizeof(array_));
grpc_server_request_registered_call(
server->server_, registered_method, &call_, &deadline_, &array_,
@@ -319,7 +322,7 @@
grpc_metadata_array_destroy(&array_);
}
- bool FinalizeResult(void** tag, bool* status) override {
+ bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE {
*tag = tag_;
if (*status && request_) {
if (payload_) {
@@ -354,10 +357,10 @@
CompletionQueue* const cq_;
ServerContext* const ctx_;
Server* const server_;
- grpc_call* call_ = nullptr;
+ grpc_call* call_;
gpr_timespec deadline_;
grpc_metadata_array array_;
- grpc_byte_buffer* payload_ = nullptr;
+ grpc_byte_buffer* payload_;
};
void Server::RequestAsyncCall(void* registered_method, ServerContext* context,
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index 3c2093c..ae60f3d 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -41,7 +41,7 @@
namespace grpc {
-ServerBuilder::ServerBuilder() {}
+ServerBuilder::ServerBuilder() : thread_pool_(nullptr) {}
void ServerBuilder::RegisterService(SynchronousService* service) {
services_.push_back(service->service());
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc
index 1aa18bc..bb3c2d1 100644
--- a/src/cpp/server/server_context.cc
+++ b/src/cpp/server/server_context.cc
@@ -44,10 +44,13 @@
// CompletionOp
-class ServerContext::CompletionOp final : public CallOpBuffer {
+class ServerContext::CompletionOp GRPC_FINAL : public CallOpBuffer {
public:
- CompletionOp();
- bool FinalizeResult(void** tag, bool* status) override;
+ // initial refs: one in the server context, one in the cq
+ CompletionOp() : refs_(2), finalized_(false), cancelled_(false) {
+ AddServerRecvClose(&cancelled_);
+ }
+ bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE;
bool CheckCancelled(CompletionQueue* cq);
@@ -55,13 +58,11 @@
private:
std::mutex mu_;
- int refs_ = 2; // initial refs: one in the server context, one in the cq
- bool finalized_ = false;
- bool cancelled_ = false;
+ int refs_;
+ bool finalized_;
+ bool cancelled_;
};
-ServerContext::CompletionOp::CompletionOp() { AddServerRecvClose(&cancelled_); }
-
void ServerContext::CompletionOp::Unref() {
std::unique_lock<std::mutex> lock(mu_);
if (--refs_ == 0) {
@@ -90,11 +91,19 @@
// ServerContext body
-ServerContext::ServerContext() {}
+ServerContext::ServerContext()
+ : completion_op_(nullptr),
+ call_(nullptr),
+ cq_(nullptr),
+ sent_initial_metadata_(false) {}
ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata,
size_t metadata_count)
- : deadline_(Timespec2Timepoint(deadline)) {
+ : completion_op_(nullptr),
+ deadline_(Timespec2Timepoint(deadline)),
+ call_(nullptr),
+ cq_(nullptr),
+ sent_initial_metadata_(false) {
for (size_t i = 0; i < metadata_count; i++) {
client_metadata_.insert(std::make_pair(
grpc::string(metadata[i].key),
diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc
index fa11ddd..5dc9bcf 100644
--- a/src/cpp/server/thread_pool.cc
+++ b/src/cpp/server/thread_pool.cc
@@ -35,7 +35,7 @@
namespace grpc {
-ThreadPool::ThreadPool(int num_threads) {
+ThreadPool::ThreadPool(int num_threads) : shutdown_(false) {
for (int i = 0; i < num_threads; i++) {
threads_.push_back(std::thread([this]() {
for (;;) {
diff --git a/src/cpp/server/thread_pool.h b/src/cpp/server/thread_pool.h
index 283618f..9c1df0b 100644
--- a/src/cpp/server/thread_pool.h
+++ b/src/cpp/server/thread_pool.h
@@ -34,6 +34,7 @@
#ifndef __GRPCPP_INTERNAL_SERVER_THREAD_POOL_H__
#define __GRPCPP_INTERNAL_SERVER_THREAD_POOL_H__
+#include <grpc++/config.h>
#include <grpc++/thread_pool_interface.h>
#include <condition_variable>
@@ -44,17 +45,17 @@
namespace grpc {
-class ThreadPool final : public ThreadPoolInterface {
+class ThreadPool GRPC_FINAL : public ThreadPoolInterface {
public:
explicit ThreadPool(int num_threads);
~ThreadPool();
- void ScheduleCallback(const std::function<void()> &callback) override;
+ void ScheduleCallback(const std::function<void()> &callback) GRPC_OVERRIDE;
private:
std::mutex mu_;
std::condition_variable cv_;
- bool shutdown_ = false;
+ bool shutdown_;
std::queue<std::function<void()>> callbacks_;
std::vector<std::thread> threads_;
};