Added mutex
This commit is contained in:
parent
56cfe7e2ce
commit
273a92c4ab
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (mastodon-cpp
|
project (mastodon-cpp
|
||||||
VERSION 0.12.2
|
VERSION 0.12.3
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ Run `make package` from the build directory to generate a tar.gz archive.
|
||||||
|
|
||||||
# Status of implementation
|
# Status of implementation
|
||||||
|
|
||||||
Feature complete as of Mastodon 2.3.0
|
Feature complete as of Mastodon 2.4.0
|
||||||
|
|
||||||
* [x] GET /api/v1/accounts/:id
|
* [x] GET /api/v1/accounts/:id
|
||||||
* [x] GET /api/v1/accounts/verify_credentials
|
* [x] GET /api/v1/accounts/verify_credentials
|
||||||
|
|
|
@ -83,7 +83,7 @@ const uint_fast16_t API::http::request(const method &meth,
|
||||||
|
|
||||||
request.setOpt<curlopts::HttpHeader>(headers);
|
request.setOpt<curlopts::HttpHeader>(headers);
|
||||||
request.setOpt<curlopts::FollowLocation>(true);
|
request.setOpt<curlopts::FollowLocation>(true);
|
||||||
request.setOpt<curlpp::options::WriteFunction>
|
request.setOpt<curlopts::WriteFunction>
|
||||||
(std::bind(&http::callback, this, _1, _2, _3, &answer));
|
(std::bind(&http::callback, this, _1, _2, _3, &answer));
|
||||||
if (!formdata.empty())
|
if (!formdata.empty())
|
||||||
{
|
{
|
||||||
|
@ -176,6 +176,7 @@ const void API::http::get_headers(string &headers) const
|
||||||
const size_t API::http::callback(char* data, size_t size, size_t nmemb,
|
const size_t API::http::callback(char* data, size_t size, size_t nmemb,
|
||||||
string *str)
|
string *str)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
if (_cancel_stream)
|
if (_cancel_stream)
|
||||||
{
|
{
|
||||||
// This throws the runtime error: Failed writing body
|
// This throws the runtime error: Failed writing body
|
||||||
|
@ -195,3 +196,8 @@ const void API::http::abort_stream()
|
||||||
{
|
{
|
||||||
cancel_stream();
|
cancel_stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::mutex &API::http::get_mutex()
|
||||||
|
{
|
||||||
|
return _mutex;
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <mutex>
|
||||||
#include <curlpp/cURLpp.hpp>
|
#include <curlpp/cURLpp.hpp>
|
||||||
#include <curlpp/Easy.hpp>
|
#include <curlpp/Easy.hpp>
|
||||||
|
|
||||||
|
@ -135,12 +136,23 @@ public:
|
||||||
[[deprecated("Will vanish in 1.0.0. Use cancel_stream() instead.")]]
|
[[deprecated("Will vanish in 1.0.0. Use cancel_stream() instead.")]]
|
||||||
const void abort_stream();
|
const void abort_stream();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets the mutex guarding the string that is written to.
|
||||||
|
*
|
||||||
|
* The mutex guards the function that writes to the string you
|
||||||
|
* specified in get_stream().
|
||||||
|
*
|
||||||
|
* @return A reference of the mutex.
|
||||||
|
*/
|
||||||
|
std::mutex &get_mutex();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const API &parent;
|
const API &parent;
|
||||||
const string _instance;
|
const string _instance;
|
||||||
const string _access_token;
|
const string _access_token;
|
||||||
string _headers;
|
string _headers;
|
||||||
bool _cancel_stream;
|
bool _cancel_stream;
|
||||||
|
std::mutex _mutex;
|
||||||
|
|
||||||
const size_t callback(char* data, size_t size, size_t nmemb,
|
const size_t callback(char* data, size_t size, size_t nmemb,
|
||||||
string *oss);
|
string *oss);
|
||||||
|
|
Reference in New Issue