我是GRPC的新手,所以如果我在这里做错了,请告诉我。我正在看greeter_async_server.cc示例代码。对于正常的请求,这似乎可以正常工作,但我想模拟一个卡在服务器上的请求,因此在处理循环中添加了睡眠。我在响应者上调用Finish之前添加了此权限,以便它在请求的实际处理逻辑中。服务器线程处于休眠状态时,它将在线程空闲之前不接受任何新请求。我尝试在服务器上的原始请求处于休眠状态时创建另一个客户端请求,但grpc服务器将不处理该请求。在服务器退出睡眠状态之前,客户端似乎一直处于阻塞状态。
我也将该程序分解为调试器,但是我看到的唯一请求是正在休眠的请求。其他线程正在等待完成队列。
我是grpc的新手,所以如果我做错了此事,请让我知道在另一个请求卡住的情况下我需要做些什么来处理请求。
void Proceed() {
if (status_ == CREATE) {
// Make this instance progress to the PROCESS state.
status_ = PROCESS;
// As part of the initial CREATE state, we *request* that the system
// start processing SayHello requests. In this request, "this" acts are
// the tag uniquely identifying the request (so that different CallData
// instances can serve different requests concurrently), in this case
// the memory address of this CallData instance.
service_->RequestSayHello(&ctx_, &request_, &responder_, cq_, cq_,
this);
} else if (status_ == PROCESS) {
// Spawn a new CallData instance to serve new clients while we process
// the one for this CallData. The instance will deallocate itself as
// part of its FINISH state.
new CallData(service_, cq_);
// The actual processing.
std::string prefix("Hello ");
reply_.set_message(prefix + request_.name());
Sleep((DWORD)-1);
// And we are done! Let the gRPC runtime know we've finished, using the
// memory address of this instance as the uniquely identifying tag for
// the event.
status_ = FINISH;
responder_.Finish(reply_, Status::OK, this);
} else {
GPR_ASSERT(status_ == FINISH);
// Once in the FINISH state, deallocate ourselves (CallData).
delete this;
}
}