|
@@ -63,6 +63,11 @@ void grpcpc::run()
|
|
|
// Container for the data we expect from the server.
|
|
|
iv::queryReply reply;
|
|
|
|
|
|
+ gpr_timespec timespec;
|
|
|
+ timespec.tv_sec = 30;//设置阻塞时间为2秒
|
|
|
+ timespec.tv_nsec = 0;
|
|
|
+ timespec.clock_type = GPR_TIMESPAN;
|
|
|
+
|
|
|
|
|
|
while(!QThread::isInterruptionRequested())
|
|
|
{
|
|
@@ -109,6 +114,7 @@ void grpcpc::run()
|
|
|
{
|
|
|
|
|
|
ClientContext context ;
|
|
|
+ context.set_deadline(timespec);
|
|
|
// qint64 time1 = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
|
|
request.set_strquerymd5(gstrqueryMD5);
|
|
@@ -167,6 +173,7 @@ void grpcpc::run()
|
|
|
{
|
|
|
|
|
|
ClientContext context ;
|
|
|
+ context.set_deadline(timespec);
|
|
|
|
|
|
qint64 time1 = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
|
@@ -186,6 +193,14 @@ void grpcpc::run()
|
|
|
std::cout << status.error_code() << ": " << status.error_message()
|
|
|
<< std::endl;
|
|
|
std::cout<<"RPC failed"<<std::endl;
|
|
|
+ if(status.error_code() == 4)
|
|
|
+ {
|
|
|
+ std::cout<<" RPC Exceed Time, Create New stub_"<<std::endl;
|
|
|
+ channel = grpc::CreateCustomChannel(
|
|
|
+ target_str, grpc::InsecureChannelCredentials(),cargs);
|
|
|
+
|
|
|
+ stub_ = iv::Upload::NewStub(channel);
|
|
|
+ }
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(900));
|
|
|
|
|
|
}
|