mirror of https://github.com/kiwix/libkiwix.git
Remove the lock.
As we now build a new request handle for every request, we don't need a lock. libcurl itself is thread safe as long as we don't share a handle.
This commit is contained in:
parent
95ebb6a492
commit
1aa8521e15
|
@ -115,11 +115,6 @@ Aria2::Aria2():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Aria2::~Aria2()
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Aria2::close()
|
void Aria2::close()
|
||||||
{
|
{
|
||||||
saveSession();
|
saveSession();
|
||||||
|
@ -139,28 +134,25 @@ std::string Aria2::doRequest(const MethodCall& methodCall)
|
||||||
std::stringstream outStream;
|
std::stringstream outStream;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
long response_code;
|
long response_code;
|
||||||
{
|
char curlErrorBuffer[CURL_ERROR_SIZE];
|
||||||
std::unique_lock<std::mutex> lock(m_lock);
|
CURL* p_curl = curl_easy_init();
|
||||||
char curlErrorBuffer[CURL_ERROR_SIZE];
|
curl_easy_setopt(p_curl, CURLOPT_URL, "http://localhost/rpc");
|
||||||
CURL* p_curl = curl_easy_init();
|
curl_easy_setopt(p_curl, CURLOPT_PORT, m_port);
|
||||||
curl_easy_setopt(p_curl, CURLOPT_URL, "http://localhost/rpc");
|
curl_easy_setopt(p_curl, CURLOPT_POST, 1L);
|
||||||
curl_easy_setopt(p_curl, CURLOPT_PORT, m_port);
|
curl_easy_setopt(p_curl, CURLOPT_ERRORBUFFER, curlErrorBuffer);
|
||||||
curl_easy_setopt(p_curl, CURLOPT_POST, 1L);
|
curl_easy_setopt(p_curl, CURLOPT_POSTFIELDSIZE, requestContent.size());
|
||||||
curl_easy_setopt(p_curl, CURLOPT_ERRORBUFFER, curlErrorBuffer);
|
curl_easy_setopt(p_curl, CURLOPT_POSTFIELDS, requestContent.c_str());
|
||||||
curl_easy_setopt(p_curl, CURLOPT_POSTFIELDSIZE, requestContent.size());
|
curl_easy_setopt(p_curl, CURLOPT_WRITEFUNCTION, &write_callback_to_iss);
|
||||||
curl_easy_setopt(p_curl, CURLOPT_POSTFIELDS, requestContent.c_str());
|
curl_easy_setopt(p_curl, CURLOPT_WRITEDATA, &outStream);
|
||||||
curl_easy_setopt(p_curl, CURLOPT_WRITEFUNCTION, &write_callback_to_iss);
|
curlErrorBuffer[0] = 0;
|
||||||
curl_easy_setopt(p_curl, CURLOPT_WRITEDATA, &outStream);
|
res = curl_easy_perform(p_curl);
|
||||||
curlErrorBuffer[0] = 0;
|
if (res != CURLE_OK) {
|
||||||
res = curl_easy_perform(p_curl);
|
LOG_ARIA_ERROR();
|
||||||
if (res != CURLE_OK) {
|
|
||||||
LOG_ARIA_ERROR();
|
|
||||||
curl_easy_cleanup(p_curl);
|
|
||||||
throw std::runtime_error("Cannot perform request");
|
|
||||||
}
|
|
||||||
curl_easy_getinfo(p_curl, CURLINFO_RESPONSE_CODE, &response_code);
|
|
||||||
curl_easy_cleanup(p_curl);
|
curl_easy_cleanup(p_curl);
|
||||||
|
throw std::runtime_error("Cannot perform request");
|
||||||
}
|
}
|
||||||
|
curl_easy_getinfo(p_curl, CURLINFO_RESPONSE_CODE, &response_code);
|
||||||
|
curl_easy_cleanup(p_curl);
|
||||||
|
|
||||||
auto responseContent = outStream.str();
|
auto responseContent = outStream.str();
|
||||||
if (response_code != 200) {
|
if (response_code != 200) {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "xmlrpc.h"
|
#include "xmlrpc.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
@ -24,12 +23,11 @@ class Aria2
|
||||||
int m_port;
|
int m_port;
|
||||||
std::string m_secret;
|
std::string m_secret;
|
||||||
std::string m_downloadDir;
|
std::string m_downloadDir;
|
||||||
std::mutex m_lock;
|
|
||||||
std::string doRequest(const MethodCall& methodCall);
|
std::string doRequest(const MethodCall& methodCall);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Aria2();
|
Aria2();
|
||||||
virtual ~Aria2();
|
virtual ~Aria2() = default;
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
std::string addUri(const std::vector<std::string>& uri, const std::vector<std::pair<std::string, std::string>>& options = {});
|
std::string addUri(const std::vector<std::string>& uri, const std::vector<std::pair<std::string, std::string>>& options = {});
|
||||||
|
|
Loading…
Reference in New Issue