I am trying to configure a grpc::ClientContext
as part of a syncrhonous request using GRPC. Note, without the context 'stuff' all is working fine.
My function looks like this:
grpc::Status Connection::syncLookup(Foo::LookupRequest &request, Foo::LookupResponse *response) {
bool failure = false;
grpc::ClientContext ctx;
Clock::time_point now = Clock::now();
auto time_since_epoch = std::chrono::duration_cast<Ms>(now.time_since_epoch()).count();
if (rpc_timeout_ms_ > 0)
{
Clock::time_point deadline = now + Ms(rpc_timeout_ms_);
ctx.set_deadline(deadline);
}
grpc::Status status = lookup_stub_->Lookup(&ctx, request, response);
if (!status.ok())
{
failure = true;
stats_worker_.record(time_since_epoch, failure, peerAddress(ctx));
return status;
}
stats_worker_.record(time_since_epoch, failure, response->serverid());
return status;
}
The error I get is:
In file included from ~/.local/include/grpc++/grpc++.h:26:
In file included from ~/.local/include/grpcpp/grpcpp.h:53:
In file included from ~/.local/include/grpcpp/client_context.h:37:
~/.local/include/grpcpp/impl/codegen/client_context.h:275:24: error: call to deleted constructor of 'grpc::TimePoint<time_point<steady_clock, duration<long long, ratio<1, 1000000000>>>>'
grpc::TimePoint<T> deadline_tp(deadline);
^ ~~~~~~~~
~/dev/cpp/grpc/lookupv2/lookup.cc:104:17: note: in instantiation of function template specialization 'grpc::ClientContext::set_deadline<std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<long long, std::ratio<1, 1000000000>>>>' requested here
ctx.set_deadline(deadline);
~/.local/include/grpcpp/impl/codegen/time.h:48:3: note: 'TimePoint' has been explicitly marked deleted here
TimePoint(const T& /*time*/) = delete;
In file included from ~/.local/include/grpc++/grpc++.h:26:
In file included from ~/.local/include/grpcpp/grpcpp.h:53:
In file included from ~/.local/include/grpcpp/client_context.h:37:
~/.local/include/grpcpp/impl/codegen/client_context.h:276:29: error: attempt to use a deleted function
deadline_ = deadline_tp.raw_time();
^
~/.local/include/grpcpp/impl/codegen/time.h:49:16: note: 'raw_time' has been explicitly marked deleted here
gpr_timespec raw_time() = delete;
where it states:
~/dev/cpp/grpc/lookupv2/lookup.cc:104:17
is the line ctx.set_deadline(deadline);
From reading around the 'the internet' this is because a copy is trying to occur when there is no copy constructor present (or something). I believe the work around is to use a std_pointer or something, but now I'm slightly out of my depth now.
It seems this isn't a completely standard issue, or atleast i haven't found anything online to suggest there is a clear cut solution to this.
Any help in getting past this error would be greatly appreciated.