in e2e-examples/gcs/sample/main.cc [89:130]
void worker(ChannelManager& channel_manager, std::atomic_size_t& read_bytes) {
// Downloads a given file N times.
for (int i = 0; i < absl::GetFlag(FLAGS_runs); i++) {
for (int j = 0; j < absl::GetFlag(FLAGS_retries); j++) {
auto channel_handle = channel_manager.GetHandle();
ReadObjectRequest request;
request.set_bucket("projects/_/buckets/" + absl::GetFlag(FLAGS_bucket));
request.set_object(absl::GetFlag(FLAGS_object));
grpc::ClientContext context;
std::unique_ptr<grpc::ClientReader<ReadObjectResponse>> reader =
channel_handle.GetStub<google::storage::v2::Storage::Stub>()
->ReadObject(&context, request);
int64_t total_bytes = 0;
ReadObjectResponse response;
while (reader->Read(&response)) {
int64_t content_size = response.checksummed_data().content().size();
total_bytes += content_size;
}
read_bytes += total_bytes;
auto status = reader->Finish();
if (!status.ok()) {
std::cerr
<< absl::StrFormat(
"Download Error: Code=%d Message=%s Retries=%d from %s",
status.error_code(), status.error_message(), j,
context.peer())
<< std::endl;
}
channel_handle.OnRpcDone(status);
// In case of retriable error, it's going to retry it
if (status.error_code() != grpc::StatusCode::CANCELLED &&
status.error_code() != grpc::StatusCode::DEADLINE_EXCEEDED) {
break;
}
}
}
}