https://github.com/grpc/grpc/blob/master/examples/cpp/helloworld/greeter_async_server.cc#L91
service_->RequestSayHello(&ctx_, &request_, &responder_, cq_, cq_,
this);
Run Code Online (Sandbox Code Playgroud)
两次出现cq_对我来说看起来很奇怪所以我深入研究了导致我
https://github.com/grpc/grpc/blob/master/include/grpcpp/impl/codegen/service_type.h#L92
void RequestAsyncUnary(int index, ServerContext* context, Message* request,
internal::ServerAsyncStreamingInterface* stream,
CompletionQueue* call_cq,
ServerCompletionQueue* notification_cq, void* tag) {
server_->RequestAsyncCall(methods_[index].get(), context, stream, call_cq,
notification_cq, tag, request);
}
Run Code Online (Sandbox Code Playgroud)
那么call_cq和之间有什么区别notification_cq?使用差异完成队列的潜在用途/好处是什么?
小智 6
当提出同样的问题时,这是来自 grpc 的 google-groups 论坛的引述。 https://groups.google.com/forum/#!topic/grpc-io/V4NAQ77PMEo
Notification_cq 取回标记,指示呼叫已开始。该调用的所有后续操作(读取、写入等)都将报告回 call_cq。对于大多数异步服务器,我的建议是使用相同的 cq。您可能不会的地方:
- 我们的同步 API 会在幕后为每个调用创建一个 cq……因此它为 notification_cq 发布一个通用事件 >queue,并且它的特定队列为 call_cq。
- 如果您希望能够控制何时接听来电与何时不接听(通过暂停对 notification_cq 的轮询)
- 我相信人们可以想到其他人。
这允许细粒度控制哪些线程处理哪些类型的事件(基于它们正在轮询的队列)。就像您可能有一个主线程轮询 notification_cq 和所有工作线程都轮询他们自己的 call_cqs 或类似的东西。
| 归档时间: |
|
| 查看次数: |
466 次 |
| 最近记录: |