【发布时间】:2019-11-02 08:42:15
【问题描述】:
在grpc Github (client) 和(server) 中提供的unary RPC 示例中,有什么方法可以检测到客户端关闭的连接吗?
例如在server.cc文件中:
std::string prefix("Hello ");
reply_.set_message(prefix + request_.name());
// 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;
int p = 0,i=0;
while(i++ < 1000000000) { // some dummy work
p = p + 10;
}
responder_.Finish(reply_, Status::OK, this);
在将响应发送回客户端之前,使用此虚拟任务,服务器将需要几秒钟。如果我们关闭客户端(例如使用Ctrl+C),服务器不会抛出任何错误。它只是简单地调用Finish,然后像Finish 成功一样释放对象。
服务器端是否有任何async 功能(处理函数)来通知我们客户端已关闭连接或客户端已终止?
谢谢!
【问题讨论】:
标签: c++ asynchronous grpc