MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ProgressCallback

Method ProgressCallback

tensorflow/core/platform/cloud/curl_http_request.cc:564–614  ·  view source on GitHub ↗

Cancels the transmission if no progress has been made for too long.

Source from the content-addressed store, hash-verified

562
563// Cancels the transmission if no progress has been made for too long.
564int CurlHttpRequest::ProgressCallback(void* this_object, curl_off_t dltotal,
565 curl_off_t dlnow, curl_off_t ultotal,
566 curl_off_t ulnow) {
567 auto that = reinterpret_cast<CurlHttpRequest*>(this_object);
568 const auto now = that->env_->NowSeconds();
569 const auto current_progress = dlnow + ulnow;
570 if (that->last_progress_timestamp_ == 0 ||
571 current_progress > that->last_progress_bytes_) {
572 // This is the first time the callback is called or some progress
573 // was made since the last tick.
574 that->last_progress_timestamp_ = now;
575 that->last_progress_bytes_ = current_progress;
576 return 0;
577 }
578
579 if (now - that->last_progress_timestamp_ > that->inactivity_timeout_secs_) {
580 double lookup_time = -1;
581 const auto lookup_time_status = that->libcurl_->curl_easy_getinfo(
582 that->curl_, CURLINFO_NAMELOOKUP_TIME, &lookup_time);
583
584 double connect_time = -1;
585 const auto connect_time_status = that->libcurl_->curl_easy_getinfo(
586 that->curl_, CURLINFO_CONNECT_TIME, &connect_time);
587
588 double pretransfer_time = -1;
589 const auto pretransfer_time_status = that->libcurl_->curl_easy_getinfo(
590 that->curl_, CURLINFO_PRETRANSFER_TIME, &pretransfer_time);
591
592 double starttransfer_time = -1;
593 const auto starttransfer_time_status = that->libcurl_->curl_easy_getinfo(
594 that->curl_, CURLINFO_PRETRANSFER_TIME, &starttransfer_time);
595
596 LOG(ERROR) << "The transmission of request " << this_object
597 << " (URI: " << that->uri_ << ") has been stuck at "
598 << current_progress << " of " << dltotal + ultotal
599 << " bytes for " << now - that->last_progress_timestamp_
600 << " seconds and will be aborted. CURL timing information: "
601 << "lookup time: " << lookup_time << " ("
602 << curl_easy_strerror(lookup_time_status)
603 << "), connect time: " << connect_time << " ("
604 << curl_easy_strerror(connect_time_status)
605 << "), pre-transfer time: " << pretransfer_time << " ("
606 << curl_easy_strerror(pretransfer_time_status)
607 << "), start-transfer time: " << starttransfer_time << " ("
608 << curl_easy_strerror(starttransfer_time_status) << ")";
609 return 1; // Will abort the request.
610 }
611
612 // No progress was made since the last call, but we should wait a bit longer.
613 return 0;
614}
615
616Status CurlHttpRequest::CURLcodeToStatus(CURLcode code,
617 const char* error_buffer) {

Callers

nothing calls this directly

Calls 2

NowSecondsMethod · 0.45
curl_easy_getinfoMethod · 0.45

Tested by

no test coverage detected