I am using grpc bidirectional streaming connection to upload images on remote server. I am splitting the given image into smaller chunks of 1MB and then perform upload operation. The uploading is working fine for the images around 4MB size but if size is > 10MB then the given deadline timer timeout and it fails always. Currently I have tested only for < 4MB and > 10MB size images.
Here is my upload function
bool FileUploadClient::upload_file(const std::string& upload_file_name)
{
bool upload_result = false;
if(m_grpc_fileupload_stub)
{
ClientContext m_context;
// set deadline timer
std::chrono::system_clock::time_point deadline = std::chrono::system_clock::now() + std::chrono::seconds(10);
m_context.set_deadline(deadline);
FileUploadGrpc::FileUploadResponse file_upload_res;
std::vector<FileUploadGrpc::FileUploadRequest> upload_request_vect;
// split file contents into chunks as file is big in size
read_file_into_chunks(upload_file_name, upload_request_vect);
std::unique_ptr<::grpc::ClientWriter<::FileUploadGrpc::FileUploadRequest>> writer(
m_grpc_fileupload_stub->UploadFileToServer(&m_context, &file_upload_res));
// Send file contents chunk by chunk to grpc end
for(const auto& upload_req_msg : upload_request_vect)
{
if(!writer->Write(upload_req_msg))
{
break; // if write fails then break
}
else
{
// I want to reset deadline timer
}
}
writer->WritesDone();
Status status = writer->Finish();
upload_result = (status.ok() && (file_upload_res.status_code() == FileUploadGrpc::FileUploadStatusCode::OK));
if(!upload_result)
{
LOG_ERROR(log_prefix << ", grpc file upload failed for: " << upload_file_name);
}
}
return upload_result;
}
As I understood that in the above give deadline timer the RPC call to upload images < 4MB completes successfully but for 10MB size I have to increase the deadline timer suitable for 10MB and that is not good idea.
So regardless of image size how can I set/reset the deadline timer after every successful write operation. Or is there any better way to do that?