Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ gRPC c++;使用相同完成队列的多个异步服务器_C++_Grpc - Fatal编程技术网

C++ gRPC c++;使用相同完成队列的多个异步服务器

C++ gRPC c++;使用相同完成队列的多个异步服务器,c++,grpc,C++,Grpc,这是关于在异步gRPC中使用完成队列的一般问题。对于每个事务,我用一个完成队列绑定它,并将其传递给函数,该函数生成对特定远程节点的RPC调用,如下所示 Status Sundial_Async_Client:: contactRemote(CompletionQueue* cq, TxnManager * txn,uint64_t node_id,SundialRequest& request, SundialResponse** response){ // Call

这是关于在异步gRPC中使用完成队列的一般问题。对于每个事务,我用一个完成队列绑定它,并将其传递给函数,该函数生成对特定远程节点的RPC调用,如下所示

Status Sundial_Async_Client:: contactRemote(CompletionQueue* cq, TxnManager * txn,uint64_t node_id,SundialRequest& request, SundialResponse** response){

        // Call object to store rpc data
        AsyncClientCall* call = new AsyncClientCall;

        // stub_->PrepareAsyncSayHello() creates an RPC object, returning
        // an instance to store in "call" but does not actually start the RPC
        // Because we are using the asynchronous API, we need to hold on to
        // the "call" instance in order to get updates on the ongoing RPC.
        call->response_reader =
            stub_->PrepareAsynccontactRemote(&call->context, request, cq);

        // StartCall initiates the RPC call
        call->response_reader->StartCall();
        call->reply=*response;
        // Request that, upon completion of the RPC, "reply" be updated with the
        // server's response; "status" with the indication of whether the operation
        // was successful. Tag the request with the memory address of the call object.
        call->response_reader->Finish(call->reply, &call->status, (void*)call);
        glob_stats->_stats[GET_THD_ID]->_req_msg_count[ request.request_type() ] ++;
        glob_stats->_stats[GET_THD_ID]->_req_msg_size[ request.request_type() ] += 
        request.SpaceUsedLong();
    return Status::OK;
}
我还使用相同的完成队列检查响应

Status Sundial_Async_Client::contactRemoteDone(CompletionQueue* cq, TxnManager * txn,uint64_t node_id, SundialResponse* response, int count){
    if(count==0){
        return Status::OK;
    }
    void* got_tag;
    bool ok = false;
    int local_count=0;
    // Block until the next result is available in the completion queue "cq".
    while (cq->Next(&got_tag, &ok)) {
            local_count++;
            // The tag in this example is the memory location of the call object
            AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag);

            // Verify that the request was completed successfully. Note that "ok"
            // corresponds solely to the request for updates introduced by Finish().
            GPR_ASSERT(ok);


            // Once we're complete, deallocate the call object.
             //doing the cleaning
            glob_stats->_stats[GET_THD_ID]->_resp_msg_count[ call->reply->response_type() ] ++;
            glob_stats->_stats[GET_THD_ID]->_resp_msg_size[ call->reply->response_type() ] += call->reply->SpaceUsedLong();
            delete call;
            if(local_count==count){
            break;
        }
        }
        
     
      return Status::OK;
   
}
Status sundail\u Async\u Client::contactRemoteDone(完成队列*cq、TxnManager*txn、uint64\u t节点id、SundalResponse*响应、整数计数){
如果(计数=0){
返回状态::OK;
}
void*got_标签;
bool ok=false;
int local_count=0;
//阻塞,直到下一个结果在完成队列“cq”中可用。
while(cq->Next(&got_标记,&ok)){
本地_计数++;
//本例中的标记是调用对象的内存位置
AsyncClientCall*call=static\u cast(got\u标记);
//验证请求是否已成功完成。请注意“确定”
//仅对应于Finish()引入的更新请求。
GPR_断言(ok);
//完成后,释放调用对象。
//打扫卫生
全局统计->全局统计[GET_THD_ID]->\u resp_msg_count[call->reply->response_type()]+;
glob_stats->_stats[GET_THD_ID]->_resp_msg_size[call->reply->response_type()]+=call->reply->SpaceUsedLong();
删除呼叫;
如果(本地计数==计数){
打破
}
}
返回状态::OK;
}
我的2个节点设置可以正常运行,但我将切换到2个以上的节点,这意味着客户端可能会向多个远程异步服务器发送异步请求。 然后我想知道是否可以使用相同的完成队列来阻止来自不同远程服务器的响应。基本上,在我的主线程中,我将传递与第一个函数中的参数相同的完成队列,并在一个循环中一起检查它们的响应。我希望我的问题有意义