From 56cfe7e2ce731eb937c25b9fc2dd5929d6be5cef Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 13 May 2018 15:41:19 +0200 Subject: [PATCH] replaced http::abort_stream() with http::cancel_stream() --- CMakeLists.txt | 2 +- examples/example09_streaming_api.cpp | 6 +++--- examples/example13_easy_stream.cpp | 4 ++-- src/http.cpp | 15 ++++++++++----- src/mastodon-cpp.hpp | 19 ++++++++++++------- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db6d124..cd7643e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastodon-cpp - VERSION 0.12.1 + VERSION 0.12.2 LANGUAGES CXX ) diff --git a/examples/example09_streaming_api.cpp b/examples/example09_streaming_api.cpp index dbce559..af6f2d6 100644 --- a/examples/example09_streaming_api.cpp +++ b/examples/example09_streaming_api.cpp @@ -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(); diff --git a/examples/example13_easy_stream.cpp b/examples/example13_easy_stream.cpp index 1483fda..7c032f1 100644 --- a/examples/example13_easy_stream.cpp +++ b/examples/example13_easy_stream.cpp @@ -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 ptr; // Start a new thread for the stream diff --git a/src/http.cpp b/src/http.cpp index 883fdd0..5d5f39a 100644 --- a/src/http.cpp +++ b/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(); } diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index b9c379d..6ffb67b 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -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.