mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-02-03 02:58:26 +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;
|
bool S3fsCurl::curl_warnings_once = false;
|
||||||
|
|
||||||
// protected by curl_handles_lock
|
// protected by curl_handles_lock
|
||||||
curltime_t S3fsCurl::curl_times;
|
std::map<const CURL*, curlprogress> S3fsCurl::curl_progress;
|
||||||
curlprogress_t S3fsCurl::curl_progress;
|
|
||||||
|
|
||||||
std::string S3fsCurl::curl_ca_bundle;
|
std::string S3fsCurl::curl_ca_bundle;
|
||||||
mimes_t S3fsCurl::mimeTypes;
|
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);
|
CURL* curl = static_cast<CURL*>(clientp);
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
progress_t p(dlnow, ulnow);
|
|
||||||
|
|
||||||
const std::lock_guard<std::mutex> lock(S3fsCurl::curl_handles_lock);
|
const std::lock_guard<std::mutex> lock(S3fsCurl::curl_handles_lock);
|
||||||
|
|
||||||
// any progress?
|
// any progress?
|
||||||
if(p != S3fsCurl::curl_progress[curl]){
|
auto& value = S3fsCurl::curl_progress[curl];
|
||||||
|
if(value.dl_progress != dlnow || value.ul_progress != ulnow){
|
||||||
// yes!
|
// yes!
|
||||||
S3fsCurl::curl_times[curl] = now;
|
value = {now, dlnow, ulnow};
|
||||||
S3fsCurl::curl_progress[curl] = p;
|
|
||||||
}else{
|
}else{
|
||||||
// timeout?
|
// 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",
|
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;
|
return CURLE_ABORTED_BY_CALLBACK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2085,8 +2083,7 @@ bool S3fsCurl::ResetHandle()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
S3fsCurl::curl_times[hCurl] = time(nullptr);
|
S3fsCurl::curl_progress[hCurl] = {time(nullptr), -1, -1};
|
||||||
S3fsCurl::curl_progress[hCurl] = progress_t(-1, -1);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2143,7 +2140,6 @@ bool S3fsCurl::DestroyCurlHandleHasLock(bool restore_pool, bool clear_internal_d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(hCurl){
|
if(hCurl){
|
||||||
S3fsCurl::curl_times.erase(hCurl);
|
|
||||||
S3fsCurl::curl_progress.erase(hCurl);
|
S3fsCurl::curl_progress.erase(hCurl);
|
||||||
sCurlPool->ReturnHandler(hCurl, restore_pool);
|
sCurlPool->ReturnHandler(hCurl, restore_pool);
|
||||||
hCurl = nullptr;
|
hCurl = nullptr;
|
||||||
@ -2695,7 +2691,7 @@ int S3fsCurl::RequestPerform(bool dontAddAuthHeaders /*=false*/)
|
|||||||
sleep(4);
|
sleep(4);
|
||||||
{
|
{
|
||||||
const std::lock_guard<std::mutex> lock(S3fsCurl::curl_handles_lock);
|
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;
|
break;
|
||||||
|
|
||||||
|
11
src/curl.h
11
src/curl.h
@ -70,9 +70,11 @@
|
|||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
// Structure / Typedefs
|
// Structure / Typedefs
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
typedef std::pair<double, double> progress_t;
|
struct curlprogress {
|
||||||
typedef std::map<CURL*, time_t> curltime_t;
|
time_t time;
|
||||||
typedef std::map<CURL*, progress_t> curlprogress_t;
|
double dl_progress;
|
||||||
|
double ul_progress;
|
||||||
|
};
|
||||||
|
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
// class S3fsCurl
|
// class S3fsCurl
|
||||||
@ -151,8 +153,7 @@ class S3fsCurl
|
|||||||
static std::string client_priv_key;
|
static std::string client_priv_key;
|
||||||
static std::string client_priv_key_type;
|
static std::string client_priv_key_type;
|
||||||
static std::string client_key_password;
|
static std::string client_key_password;
|
||||||
static curltime_t curl_times;
|
static std::map<const CURL*, curlprogress> curl_progress;
|
||||||
static curlprogress_t curl_progress;
|
|
||||||
static std::string curl_ca_bundle;
|
static std::string curl_ca_bundle;
|
||||||
static mimes_t mimeTypes;
|
static mimes_t mimeTypes;
|
||||||
static std::string userAgent;
|
static std::string userAgent;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user