fixed stale curl handle bug; fixed 100% cpu bug

git-svn-id: http://s3fs.googlecode.com/svn/trunk@177 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
rrizun 2008-08-10 22:51:27 +00:00
parent a2d7ad4225
commit f3549de9d8

View File

@ -118,10 +118,12 @@ public:
}
};
static stack<CURL*> curl_handles;
static pthread_mutex_t curl_handles_lock;
typedef pair<double, double> progress_t;
static map<CURL*, time_t> curl_times;
static map<CURL*, progress_t> curl_progress;
static pthread_mutex_t curl_progress_lock;
// homegrown timeout mechanism
static int
@ -131,13 +133,10 @@ my_curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, do
time_t now = time(0);
progress_t p(dlnow, ulnow);
auto_lock lock(curl_progress_lock);
//###cout << "/dlnow=" << dlnow << "/ulnow=" << ulnow << endl;
auto_lock lock(curl_handles_lock);
// first time?
if (dlnow == 0 and ulnow == 0) {
curl_times.erase(curl);
curl_progress.erase(curl);
} else {
// any progress?
if (p != curl_progress[curl]) {
// yes!
@ -148,14 +147,10 @@ my_curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, do
if (now - curl_times[curl] > readwrite_timeout)
return CURLE_ABORTED_BY_CALLBACK;
}
}
return 0;
}
static stack<CURL*> curl_handles;
static pthread_mutex_t curl_handles_lock;
static CURL*
alloc_curl_handle() {
CURL* curl;
@ -178,6 +173,10 @@ alloc_curl_handle() {
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_curl_progress);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, curl);
time_t now = time(0);
curl_times[curl] = now;
curl_progress[curl] = progress_t(-1,-1);
return curl;
}
@ -186,6 +185,8 @@ return_curl_handle(CURL* curl_handle) {
if (curl_handle != 0) {
auto_lock lock(curl_handles_lock);
curl_handles.push(curl_handle);
curl_times.erase(curl_handle);
curl_progress.erase(curl_handle);
}
}
@ -1241,7 +1242,7 @@ s3fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset,
if (NextMarker.size() > 0)
query += "&marker=" + urlEncode(NextMarker);
query += "&max-keys=20";
query += "&max-keys=50";
string url = host + resource + "?"+ query;
@ -1361,7 +1362,8 @@ s3fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset,
long milliseconds;
VERIFY(curl_multi_timeout(multi_handle.get(), &milliseconds));
if (milliseconds < 0)
milliseconds = 50;
if (milliseconds > 0) {
struct timeval timeout;
timeout.tv_sec = 1000*milliseconds/1000000;
@ -1469,7 +1471,6 @@ static void* s3fs_init(struct fuse_conn_info *conn) {
CRYPTO_set_id_callback(id_function);
curl_global_init(CURL_GLOBAL_ALL);
pthread_mutex_init(&curl_handles_lock, NULL);
pthread_mutex_init(&curl_progress_lock, NULL);
pthread_mutex_init(&s3fs_descriptors_lock, NULL);
pthread_mutex_init(&stat_cache_lock, NULL);
//
@ -1503,7 +1504,6 @@ static void s3fs_destroy(void*) {
mutex_buf = NULL;
curl_global_cleanup();
pthread_mutex_destroy(&curl_handles_lock);
pthread_mutex_destroy(&curl_progress_lock);
pthread_mutex_destroy(&s3fs_descriptors_lock);
pthread_mutex_destroy(&stat_cache_lock);
}