replaced http::abort_stream() with http::cancel_stream()
This commit is contained in:
parent
fe2a09878b
commit
56cfe7e2ce
@ -1,6 +1,6 @@
|
||||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastodon-cpp
|
||||
VERSION 0.12.1
|
||||
VERSION 0.12.2
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
@ -44,8 +44,8 @@ int main(int argc, char *argv[])
|
||||
answer.clear();
|
||||
if (counter == 10)
|
||||
{
|
||||
std::cerr << "Aborting...\n";
|
||||
ptr->abort_stream();
|
||||
std::cerr << "Cancelling...\n";
|
||||
ptr->cancel_stream();
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
@ -63,7 +63,7 @@ int main(int argc, char *argv[])
|
||||
answer, ptr);
|
||||
});
|
||||
std::this_thread::sleep_for(std::chrono::seconds(20));
|
||||
ptr->abort_stream();
|
||||
ptr->cancel_stream();
|
||||
std::cout << answer;
|
||||
std::cout << '\n';
|
||||
tag.join();
|
||||
|
@ -35,11 +35,11 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "I'll show you the public timeline. Press CTRL-C to abort\n";
|
||||
cout << "I'll show you the public timeline. Press CTRL-C to cancel\n";
|
||||
|
||||
// These have to be static in order to use them in- and outside the thread
|
||||
static std::string stream;
|
||||
// You can abort the stream with this pointer (ptr->abort_stream())
|
||||
// You can cancel the stream with this pointer (ptr->cancel_stream())
|
||||
static std::unique_ptr<Mastodon::API::http> ptr;
|
||||
|
||||
// Start a new thread for the stream
|
||||
|
15
src/http.cpp
15
src/http.cpp
@ -34,7 +34,7 @@ API::http::http(const API &api, const string &instance,
|
||||
: parent(api)
|
||||
, _instance(instance)
|
||||
, _access_token(access_token)
|
||||
, _abort_stream(false)
|
||||
, _cancel_stream(false)
|
||||
{
|
||||
curlpp::initialize();
|
||||
}
|
||||
@ -137,10 +137,10 @@ const uint_fast16_t API::http::request(const method &meth,
|
||||
}
|
||||
catch (curlpp::RuntimeError &e)
|
||||
{
|
||||
// This error is thrown if http.abort_stream() is used.
|
||||
// This error is thrown if http.cancel_stream() is used.
|
||||
if (std::strncmp(e.what(), "Failed writing body", 19) == 0)
|
||||
{
|
||||
ttdebug << "Request was aborted by user\n";
|
||||
ttdebug << "Request was cancelled by user\n";
|
||||
return 14;
|
||||
}
|
||||
|
||||
@ -176,7 +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,
|
||||
string *str)
|
||||
{
|
||||
if (_abort_stream)
|
||||
if (_cancel_stream)
|
||||
{
|
||||
// This throws the runtime error: Failed writing body
|
||||
return 0;
|
||||
@ -186,7 +186,12 @@ const size_t API::http::callback(char* data, size_t size, size_t nmemb,
|
||||
return size * nmemb;
|
||||
};
|
||||
|
||||
const void API::http::cancel_stream()
|
||||
{
|
||||
_cancel_stream = true;
|
||||
}
|
||||
|
||||
const void API::http::abort_stream()
|
||||
{
|
||||
_abort_stream = true;
|
||||
cancel_stream();
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace Mastodon
|
||||
* | 11 | Invalid call |
|
||||
* | 12 | Not implemented |
|
||||
* | 13 | URL changed (HTTP 301 or 308) |
|
||||
* | 14 | Aborted by user |
|
||||
* | 14 | Cancelled by user |
|
||||
* | 15 | Network error (curlpp exception) |
|
||||
* | 100 - 999 | HTTP status codes |
|
||||
* | 65535 | Unknown error |
|
||||
@ -121,13 +121,18 @@ public:
|
||||
const void get_headers(string &headers) const;
|
||||
|
||||
/*!
|
||||
* @brief Aborts the stream. Use only with streams.
|
||||
* @brief Cancels the stream. Use only with streams.
|
||||
*
|
||||
* Aborts the stream next time data comes in. Can take a few
|
||||
* Cancels the stream next time data comes in. Can take a few
|
||||
* seconds.
|
||||
* This works only with streams, because only streams have an
|
||||
* own http object.
|
||||
*
|
||||
* @since 0.12.2
|
||||
*/
|
||||
const void cancel_stream();
|
||||
|
||||
[[deprecated("Will vanish in 1.0.0. Use cancel_stream() instead.")]]
|
||||
const void abort_stream();
|
||||
|
||||
private:
|
||||
@ -135,7 +140,7 @@ public:
|
||||
const string _instance;
|
||||
const string _access_token;
|
||||
string _headers;
|
||||
bool _abort_stream;
|
||||
bool _cancel_stream;
|
||||
|
||||
const size_t callback(char* data, size_t size, size_t nmemb,
|
||||
string *oss);
|
||||
@ -426,7 +431,7 @@ public:
|
||||
* @param parameters A Mastodon::API::parametermap containing parameters
|
||||
* @param answer The answer from the server. Events with JSON-payload.
|
||||
* @param ptr Pointer to the http object. Can be used to call
|
||||
* ptr->abort_stream()
|
||||
* ptr->cancel_stream()
|
||||
*
|
||||
* @return @ref error "Error code". If the URL has permanently changed, 13
|
||||
* is returned and answer is set to the new URL.
|
||||
@ -442,7 +447,7 @@ public:
|
||||
* @param call A call defined in Mastodon::API::v1
|
||||
* @param answer The answer from the server. Events with JSON-payload.
|
||||
* @param ptr Pointer to the http object. Can be used to call
|
||||
* ptr->abort_stream()
|
||||
* ptr->cancel_stream()
|
||||
*
|
||||
* @return @ref error "Error code". If the URL has permanently changed, 13
|
||||
* is returned and answer is set to the new URL.
|
||||
@ -458,7 +463,7 @@ public:
|
||||
* @param answer The answer from the server. Usually JSON. On error an
|
||||
* empty string.
|
||||
* @param ptr Pointer to the http object. Can be used to call
|
||||
* ptr->abort_stream()
|
||||
* ptr->cancel_stream()
|
||||
*
|
||||
* @return @ref error "Error code". If the URL has permanently changed, 13
|
||||
* is returned and answer is set to the new URL.
|
||||
|
Reference in New Issue
Block a user