[#127] set timeout for keeplive grpc
This commit is contained in:
parent
f21c45b362
commit
14d2450e11
|
|
@ -46,7 +46,7 @@ namespace etcdv3
|
|||
AsyncLeaseKeepAliveAction(etcdv3::ActionParameters const ¶m);
|
||||
AsyncLeaseKeepAliveResponse ParseResponse();
|
||||
|
||||
etcd::Response Refresh();
|
||||
etcd::Response Refresh(int ttl);
|
||||
void CancelKeepAlive();
|
||||
bool Cancelled() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ void etcd::KeepAlive::refresh()
|
|||
#endif
|
||||
} else {
|
||||
if (this->continue_next.load()) {
|
||||
auto resp = this->stubs->call->Refresh();
|
||||
auto resp = this->stubs->call->Refresh(ttl);
|
||||
if (!resp.is_ok()) {
|
||||
throw std::runtime_error("Failed to refresh lease: error code: " + std::to_string(resp.error_code()) +
|
||||
", message: " + resp.error_message());
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ etcdv3::AsyncLeaseKeepAliveResponse etcdv3::AsyncLeaseKeepAliveAction::ParseResp
|
|||
return lease_resp;
|
||||
}
|
||||
|
||||
etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh()
|
||||
etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh(int ttl)
|
||||
{
|
||||
std::lock_guard<std::mutex> scope_lock(this->protect_is_cancelled);
|
||||
|
||||
|
|
@ -108,13 +108,16 @@ etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh()
|
|||
|
||||
void *got_tag = nullptr;
|
||||
bool ok = false;
|
||||
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(ttl);
|
||||
|
||||
stream->Write(leasekeepalive_request, (void *)etcdv3::KEEPALIVE_WRITE);
|
||||
// wait write finish
|
||||
if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void *)etcdv3::KEEPALIVE_WRITE) {
|
||||
if (cq_.AsyncNext(&got_tag, &ok, deadline) == CompletionQueue::NextStatus::GOT_EVENT &&
|
||||
ok && got_tag == (void *)etcdv3::KEEPALIVE_WRITE) {
|
||||
stream->Read(&reply, (void*)etcdv3::KEEPALIVE_READ);
|
||||
// wait read finish
|
||||
if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void *)etcdv3::KEEPALIVE_READ) {
|
||||
if (cq_.AsyncNext(&got_tag, &ok, deadline) == CompletionQueue::NextStatus::GOT_EVENT &&
|
||||
ok && got_tag == (void *)etcdv3::KEEPALIVE_READ) {
|
||||
auto resp = ParseResponse();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_timepoint);
|
||||
|
|
|
|||
Loading…
Reference in New Issue