diff options
author | Sree Kuchibhotla <sreek@google.com> | 2016-04-21 12:28:09 -0700 |
---|---|---|
committer | Sree Kuchibhotla <sreek@google.com> | 2016-04-21 12:28:15 -0700 |
commit | 1f5e262589c84c2b5eb9416211bffd1f32998009 (patch) | |
tree | 80dfd9160b78e4b54e1b10ace569ced9b181e49f /src/cpp/server | |
parent | 020cdb8b21e9240ace67a58e10e01e600914c8c9 (diff) |
Add the option of adding a non-listening server completion queue. This makes writing certain test cases (like hybrid_end2end tests) easier
Diffstat (limited to 'src/cpp/server')
-rw-r--r-- | src/cpp/server/server_builder.cc | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index 68cc38258c..5445d3e13b 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -46,8 +46,9 @@ ServerBuilder::ServerBuilder() grpc_compression_options_init(&compression_options_); } -std::unique_ptr<ServerCompletionQueue> ServerBuilder::AddCompletionQueue() { - ServerCompletionQueue* cq = new ServerCompletionQueue(); +std::unique_ptr<ServerCompletionQueue> ServerBuilder::AddCompletionQueue( + bool is_frequently_polled) { + ServerCompletionQueue* cq = new ServerCompletionQueue(is_frequently_polled); cqs_.push_back(cq); return std::unique_ptr<ServerCompletionQueue>(cq); } @@ -105,8 +106,17 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() { std::unique_ptr<Server> server( new Server(thread_pool.release(), true, max_message_size_, &args)); for (auto cq = cqs_.begin(); cq != cqs_.end(); ++cq) { - grpc_server_register_completion_queue(server->server_, (*cq)->cq(), - nullptr); + // A completion queue that is not polled frequently (by calling Next() or + // AsyncNext()) is not safe to use for listening to incoming channels. + // Register all such completion queues as non-listening completion queues + // with the GRPC core library. + if ((*cq)->IsFrequentlyPolled()) { + grpc_server_register_completion_queue(server->server_, (*cq)->cq(), + nullptr); + } else { + grpc_server_register_non_listening_completion_queue(server->server_, + (*cq)->cq(), nullptr); + } } for (auto service = services_.begin(); service != services_.end(); service++) { |