diff --git a/etcd/v3/AsyncLeaseKeepAliveAction.hpp b/etcd/v3/AsyncLeaseKeepAliveAction.hpp index 7458ad0..8d9bfef 100644 --- a/etcd/v3/AsyncLeaseKeepAliveAction.hpp +++ b/etcd/v3/AsyncLeaseKeepAliveAction.hpp @@ -16,6 +16,7 @@ using grpc::ClientAsyncResponseReader; namespace etcdv3 { class AsyncLeaseKeepAliveAction : public etcdv3::Action { + enum class Type { READ = 1, WRITE = 2, CONNECT = 3, WRITES_DONE = 4, FINISH = 5 }; public: AsyncLeaseKeepAliveAction(etcdv3::ActionParameters param); AsyncLeaseKeepAliveResponse ParseResponse(); @@ -24,8 +25,6 @@ class AsyncLeaseKeepAliveAction : public etcdv3::Action { private: LeaseKeepAliveResponse reply; std::unique_ptr> stream; - - char* doneTag = "writes done"; }; } // namespace etcdv3 diff --git a/src/v3/AsyncLeaseKeepAliveAction.cpp b/src/v3/AsyncLeaseKeepAliveAction.cpp index a23c174..0c787d0 100644 --- a/src/v3/AsyncLeaseKeepAliveAction.cpp +++ b/src/v3/AsyncLeaseKeepAliveAction.cpp @@ -8,10 +8,7 @@ using etcdserverpb::RangeRequest; using etcdserverpb::RangeResponse; etcdv3::AsyncLeaseKeepAliveAction::AsyncLeaseKeepAliveAction(etcdv3::ActionParameters param) : etcdv3::Action(param) { - char* createTag = "create"; - char* writeTag = "write"; - - stream = parameters.lease_stub->AsyncLeaseKeepAlive(&context, &cq_, (void*)createTag); + stream = parameters.lease_stub->AsyncLeaseKeepAlive(&context, &cq_, reinterpret_cast(Type::CONNECT)); LeaseKeepAliveRequest request; request.set_id(parameters.lease_id); @@ -19,15 +16,15 @@ etcdv3::AsyncLeaseKeepAliveAction::AsyncLeaseKeepAliveAction(etcdv3::ActionParam // wait "create" success (the stream becomes ready) void* got_tag; bool ok = false; - if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void*)createTag) { - stream->Write(request, (void*)writeTag); + if (cq_.Next(&got_tag, &ok) && ok && got_tag == reinterpret_cast(Type::CONNECT)) { + stream->Write(request, reinterpret_cast(Type::WRITE)); } else { throw std::runtime_error("failed to create a keepalive connection"); } // wait "write" (LeaseKeepAliveRequest) success, and start to read the first // reply - if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void*)writeTag) { + if (cq_.Next(&got_tag, &ok) && ok && got_tag == reinterpret_cast(Type::WRITE)) { stream->Read(&reply, (void*)this); } else { throw std::runtime_error("failed to write LeaseKeepAliveRequest to server"); @@ -42,14 +39,14 @@ void etcdv3::AsyncLeaseKeepAliveAction::waitForResponse() { if (ok == false) { break; } - if (got_tag == (void*)doneTag) { + if (got_tag == reinterpret_cast(Type::WRITES_DONE)) { cq_.Shutdown(); break; } if (got_tag == (void*)this) // read tag { if (reply.ByteSize()) { - stream->WritesDone((void*)doneTag); + stream->WritesDone(reinterpret_cast(Type::WRITES_DONE)); } else { stream->Read(&reply, (void*)this); }