aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/support/cpu_posix.c2
-rw-r--r--src/cpp/server/server.cc156
-rw-r--r--test/cpp/client/channel_arguments_test.cc12
-rw-r--r--test/cpp/end2end/async_end2end_test.cc12
4 files changed, 90 insertions, 92 deletions
diff --git a/src/core/support/cpu_posix.c b/src/core/support/cpu_posix.c
index 91f722530c..91ce80c364 100644
--- a/src/core/support/cpu_posix.c
+++ b/src/core/support/cpu_posix.c
@@ -35,8 +35,6 @@
#ifdef GPR_CPU_POSIX
-#include "src/core/support/cpu.h"
-
#include <errno.h>
#include <unistd.h>
#include <string.h>
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 7cccc58afd..f565d3aa5d 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -49,84 +49,6 @@
namespace grpc {
-Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
- ServerCredentials* creds)
- : started_(false),
- shutdown_(false),
- num_running_cb_(0),
- thread_pool_(thread_pool),
- thread_pool_owned_(thread_pool_owned),
- secure_(creds != nullptr) {
- if (creds) {
- server_ =
- grpc_secure_server_create(creds->GetRawCreds(), cq_.cq(), nullptr);
- } else {
- server_ = grpc_server_create(cq_.cq(), nullptr);
- }
-}
-
-Server::Server() {
- // Should not be called.
- GPR_ASSERT(false);
-}
-
-Server::~Server() {
- std::unique_lock<std::mutex> lock(mu_);
- if (started_ && !shutdown_) {
- lock.unlock();
- Shutdown();
- } else {
- lock.unlock();
- }
- grpc_server_destroy(server_);
- if (thread_pool_owned_) {
- delete thread_pool_;
- }
-}
-
-bool Server::RegisterService(RpcService* service) {
- for (int i = 0; i < service->GetMethodCount(); ++i) {
- RpcServiceMethod* method = service->GetMethod(i);
- void* tag =
- grpc_server_register_method(server_, method->name(), nullptr, cq_.cq());
- if (!tag) {
- gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
- method->name());
- return false;
- }
- sync_methods_.emplace_back(method, tag);
- }
- return true;
-}
-
-bool Server::RegisterAsyncService(AsynchronousService* service) {
- GPR_ASSERT(service->dispatch_impl_ == nullptr &&
- "Can only register an asynchronous service against one server.");
- service->dispatch_impl_ = this;
- service->request_args_ = new void* [service->method_count_];
- for (size_t i = 0; i < service->method_count_; ++i) {
- void* tag =
- grpc_server_register_method(server_, service->method_names_[i], nullptr,
- service->completion_queue()->cq());
- if (!tag) {
- gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
- service->method_names_[i]);
- return false;
- }
- service->request_args_[i] = tag;
- }
- return true;
-}
-
-int Server::AddPort(const grpc::string& addr) {
- GPR_ASSERT(!started_);
- if (secure_) {
- return grpc_server_add_secure_http2_port(server_, addr.c_str());
- } else {
- return grpc_server_add_http2_port(server_, addr.c_str());
- }
-}
-
class Server::SyncRequest final : public CompletionQueueTag {
public:
SyncRequest(RpcServiceMethod* method, void* tag)
@@ -247,6 +169,84 @@ class Server::SyncRequest final : public CompletionQueueTag {
grpc_completion_queue* cq_;
};
+Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
+ ServerCredentials* creds)
+ : started_(false),
+ shutdown_(false),
+ num_running_cb_(0),
+ thread_pool_(thread_pool),
+ thread_pool_owned_(thread_pool_owned),
+ secure_(creds != nullptr) {
+ if (creds) {
+ server_ =
+ grpc_secure_server_create(creds->GetRawCreds(), cq_.cq(), nullptr);
+ } else {
+ server_ = grpc_server_create(cq_.cq(), nullptr);
+ }
+}
+
+Server::Server() {
+ // Should not be called.
+ GPR_ASSERT(false);
+}
+
+Server::~Server() {
+ std::unique_lock<std::mutex> lock(mu_);
+ if (started_ && !shutdown_) {
+ lock.unlock();
+ Shutdown();
+ } else {
+ lock.unlock();
+ }
+ grpc_server_destroy(server_);
+ if (thread_pool_owned_) {
+ delete thread_pool_;
+ }
+}
+
+bool Server::RegisterService(RpcService* service) {
+ for (int i = 0; i < service->GetMethodCount(); ++i) {
+ RpcServiceMethod* method = service->GetMethod(i);
+ void* tag =
+ grpc_server_register_method(server_, method->name(), nullptr, cq_.cq());
+ if (!tag) {
+ gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
+ method->name());
+ return false;
+ }
+ sync_methods_.emplace_back(method, tag);
+ }
+ return true;
+}
+
+bool Server::RegisterAsyncService(AsynchronousService* service) {
+ GPR_ASSERT(service->dispatch_impl_ == nullptr &&
+ "Can only register an asynchronous service against one server.");
+ service->dispatch_impl_ = this;
+ service->request_args_ = new void* [service->method_count_];
+ for (size_t i = 0; i < service->method_count_; ++i) {
+ void* tag =
+ grpc_server_register_method(server_, service->method_names_[i], nullptr,
+ service->completion_queue()->cq());
+ if (!tag) {
+ gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
+ service->method_names_[i]);
+ return false;
+ }
+ service->request_args_[i] = tag;
+ }
+ return true;
+}
+
+int Server::AddPort(const grpc::string& addr) {
+ GPR_ASSERT(!started_);
+ if (secure_) {
+ return grpc_server_add_secure_http2_port(server_, addr.c_str());
+ } else {
+ return grpc_server_add_http2_port(server_, addr.c_str());
+ }
+}
+
bool Server::Start() {
GPR_ASSERT(!started_);
started_ = true;
diff --git a/test/cpp/client/channel_arguments_test.cc b/test/cpp/client/channel_arguments_test.cc
index d98b38ab68..01c56cb795 100644
--- a/test/cpp/client/channel_arguments_test.cc
+++ b/test/cpp/client/channel_arguments_test.cc
@@ -52,14 +52,14 @@ TEST_F(ChannelArgumentsTest, SetInt) {
ChannelArguments channel_args;
// Empty arguments.
SetChannelArgs(channel_args, &args);
- EXPECT_EQ(0, args.num_args);
+ EXPECT_EQ(static_cast<size_t>(0), args.num_args);
grpc::string key("key0");
channel_args.SetInt(key, 0);
// Clear key early to make sure channel_args takes a copy
key = "";
SetChannelArgs(channel_args, &args);
- EXPECT_EQ(1, args.num_args);
+ EXPECT_EQ(static_cast<size_t>(1), args.num_args);
EXPECT_EQ(GRPC_ARG_INTEGER, args.args[0].type);
EXPECT_STREQ("key0", args.args[0].key);
EXPECT_EQ(0, args.args[0].value.integer);
@@ -68,7 +68,7 @@ TEST_F(ChannelArgumentsTest, SetInt) {
channel_args.SetInt(key, 1);
key = "";
SetChannelArgs(channel_args, &args);
- EXPECT_EQ(2, args.num_args);
+ EXPECT_EQ(static_cast<size_t>(2), args.num_args);
// We do not enforce order on the arguments.
for (size_t i = 0; i < args.num_args; i++) {
EXPECT_EQ(GRPC_ARG_INTEGER, args.args[i].type);
@@ -85,7 +85,7 @@ TEST_F(ChannelArgumentsTest, SetString) {
ChannelArguments channel_args;
// Empty arguments.
SetChannelArgs(channel_args, &args);
- EXPECT_EQ(0, args.num_args);
+ EXPECT_EQ(static_cast<size_t>(0), args.num_args);
grpc::string key("key0");
grpc::string val("val0");
@@ -94,7 +94,7 @@ TEST_F(ChannelArgumentsTest, SetString) {
key = "";
val = "";
SetChannelArgs(channel_args, &args);
- EXPECT_EQ(1, args.num_args);
+ EXPECT_EQ(static_cast<size_t>(1), args.num_args);
EXPECT_EQ(GRPC_ARG_STRING, args.args[0].type);
EXPECT_STREQ("key0", args.args[0].key);
EXPECT_STREQ("val0", args.args[0].value.string);
@@ -103,7 +103,7 @@ TEST_F(ChannelArgumentsTest, SetString) {
val = "val1";
channel_args.SetString(key, val);
SetChannelArgs(channel_args, &args);
- EXPECT_EQ(2, args.num_args);
+ EXPECT_EQ(static_cast<size_t>(2), args.num_args);
// We do not enforce order on the arguments.
for (size_t i = 0; i < args.num_args; i++) {
EXPECT_EQ(GRPC_ARG_STRING, args.args[i].type);
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 79160bfaa5..248e054e49 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -364,7 +364,7 @@ TEST_F(AsyncEnd2endTest, ClientInitialMetadataRpc) {
auto client_initial_metadata = srv_ctx.client_metadata();
EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second);
EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second);
- EXPECT_EQ(2, client_initial_metadata.size());
+ EXPECT_EQ(static_cast<size_t>(2), client_initial_metadata.size());
client_ok(1);
send_response.set_message(recv_request.message());
@@ -414,7 +414,7 @@ TEST_F(AsyncEnd2endTest, ServerInitialMetadataRpc) {
auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
EXPECT_EQ(meta1.second, server_initial_metadata.find(meta1.first)->second);
EXPECT_EQ(meta2.second, server_initial_metadata.find(meta2.first)->second);
- EXPECT_EQ(2, server_initial_metadata.size());
+ EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size());
send_response.set_message(recv_request.message());
response_writer.Finish(send_response, Status::OK, tag(5));
@@ -470,7 +470,7 @@ TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) {
auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
EXPECT_EQ(meta1.second, server_trailing_metadata.find(meta1.first)->second);
EXPECT_EQ(meta2.second, server_trailing_metadata.find(meta2.first)->second);
- EXPECT_EQ(2, server_trailing_metadata.size());
+ EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
}
TEST_F(AsyncEnd2endTest, MetadataRpc) {
@@ -510,7 +510,7 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) {
auto client_initial_metadata = srv_ctx.client_metadata();
EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second);
EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second);
- EXPECT_EQ(2, client_initial_metadata.size());
+ EXPECT_EQ(static_cast<size_t>(2), client_initial_metadata.size());
client_ok(1);
srv_ctx.AddInitialMetadata(meta3.first, meta3.second);
@@ -522,7 +522,7 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) {
auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
EXPECT_EQ(meta3.second, server_initial_metadata.find(meta3.first)->second);
EXPECT_EQ(meta4.second, server_initial_metadata.find(meta4.first)->second);
- EXPECT_EQ(2, server_initial_metadata.size());
+ EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size());
send_response.set_message(recv_request.message());
srv_ctx.AddTrailingMetadata(meta5.first, meta5.second);
@@ -539,7 +539,7 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) {
auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
EXPECT_EQ(meta5.second, server_trailing_metadata.find(meta5.first)->second);
EXPECT_EQ(meta6.second, server_trailing_metadata.find(meta6.first)->second);
- EXPECT_EQ(2, server_trailing_metadata.size());
+ EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
}
} // namespace
} // namespace testing