mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-01-23 22:08:24 +00:00
Simplify curl progress tracking (#2486)
Use a struct with named fields instead of a pair for clarity and use a single map to store the structs for efficiency.
This commit is contained in:
parent
ec183d0d9a
commit
50d5a73f84
20
src/curl.cpp
20
src/curl.cpp
@ -118,8 +118,7 @@ std::string S3fsCurl::client_key_password;
|
||||
bool S3fsCurl::curl_warnings_once = false;
|
||||
|
||||
// protected by curl_handles_lock
|
||||
curltime_t S3fsCurl::curl_times;
|
||||
curlprogress_t S3fsCurl::curl_progress;
|
||||
std::map<const CURL*, curlprogress> S3fsCurl::curl_progress;
|
||||
|
||||
std::string S3fsCurl::curl_ca_bundle;
|
||||
mimes_t S3fsCurl::mimeTypes;
|
||||
@ -313,20 +312,19 @@ int S3fsCurl::CurlProgress(void *clientp, double dltotal, double dlnow, double u
|
||||
{
|
||||
CURL* curl = static_cast<CURL*>(clientp);
|
||||
time_t now = time(nullptr);
|
||||
progress_t p(dlnow, ulnow);
|
||||
|
||||
const std::lock_guard<std::mutex> lock(S3fsCurl::curl_handles_lock);
|
||||
|
||||
// any progress?
|
||||
if(p != S3fsCurl::curl_progress[curl]){
|
||||
auto& value = S3fsCurl::curl_progress[curl];
|
||||
if(value.dl_progress != dlnow || value.ul_progress != ulnow){
|
||||
// yes!
|
||||
S3fsCurl::curl_times[curl] = now;
|
||||
S3fsCurl::curl_progress[curl] = p;
|
||||
value = {now, dlnow, ulnow};
|
||||
}else{
|
||||
// timeout?
|
||||
if(now - S3fsCurl::curl_times[curl] > readwrite_timeout){
|
||||
if(now - value.time > readwrite_timeout){
|
||||
S3FS_PRN_ERR("timeout now: %lld, curl_times[curl]: %lld, readwrite_timeout: %lld",
|
||||
static_cast<long long>(now), static_cast<long long>((S3fsCurl::curl_times[curl])), static_cast<long long>(readwrite_timeout));
|
||||
static_cast<long long>(now), static_cast<long long>((value.time)), static_cast<long long>(readwrite_timeout));
|
||||
return CURLE_ABORTED_BY_CALLBACK;
|
||||
}
|
||||
}
|
||||
@ -2085,8 +2083,7 @@ bool S3fsCurl::ResetHandle()
|
||||
}
|
||||
}
|
||||
|
||||
S3fsCurl::curl_times[hCurl] = time(nullptr);
|
||||
S3fsCurl::curl_progress[hCurl] = progress_t(-1, -1);
|
||||
S3fsCurl::curl_progress[hCurl] = {time(nullptr), -1, -1};
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -2143,7 +2140,6 @@ bool S3fsCurl::DestroyCurlHandleHasLock(bool restore_pool, bool clear_internal_d
|
||||
}
|
||||
|
||||
if(hCurl){
|
||||
S3fsCurl::curl_times.erase(hCurl);
|
||||
S3fsCurl::curl_progress.erase(hCurl);
|
||||
sCurlPool->ReturnHandler(hCurl, restore_pool);
|
||||
hCurl = nullptr;
|
||||
@ -2695,7 +2691,7 @@ int S3fsCurl::RequestPerform(bool dontAddAuthHeaders /*=false*/)
|
||||
sleep(4);
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(S3fsCurl::curl_handles_lock);
|
||||
S3fsCurl::curl_times[hCurl] = time(nullptr);
|
||||
S3fsCurl::curl_progress[hCurl] = {time(nullptr), -1, -1};
|
||||
}
|
||||
break;
|
||||
|
||||
|
11
src/curl.h
11
src/curl.h
@ -70,9 +70,11 @@
|
||||
//----------------------------------------------
|
||||
// Structure / Typedefs
|
||||
//----------------------------------------------
|
||||
typedef std::pair<double, double> progress_t;
|
||||
typedef std::map<CURL*, time_t> curltime_t;
|
||||
typedef std::map<CURL*, progress_t> curlprogress_t;
|
||||
struct curlprogress {
|
||||
time_t time;
|
||||
double dl_progress;
|
||||
double ul_progress;
|
||||
};
|
||||
|
||||
//----------------------------------------------
|
||||
// class S3fsCurl
|
||||
@ -151,8 +153,7 @@ class S3fsCurl
|
||||
static std::string client_priv_key;
|
||||
static std::string client_priv_key_type;
|
||||
static std::string client_key_password;
|
||||
static curltime_t curl_times;
|
||||
static curlprogress_t curl_progress;
|
||||
static std::map<const CURL*, curlprogress> curl_progress;
|
||||
static std::string curl_ca_bundle;
|
||||
static mimes_t mimeTypes;
|
||||
static std::string userAgent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user