Mercurial > minori
changeset 397:811697ad826a
http: do proper global init/cleanup of libcurl
this is done automagically using RAII
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 07 Nov 2025 08:39:24 -0500 |
| parents | 8ed3b5e8f205 |
| children | 650a9159a0e7 |
| files | include/core/http.h src/core/http.cc src/main.cc |
| diffstat | 3 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/include/core/http.h Fri Nov 07 07:56:03 2025 -0500 +++ b/include/core/http.h Fri Nov 07 08:39:24 2025 -0500 @@ -11,6 +11,17 @@ namespace HTTP { +/* Global state init/quit */ +void Init(); +void Quit(); + +/* helper class that automatically init/deinit as constructors + * and destructors */ +struct Initializer { + Initializer() { Init(); } + ~Initializer() { Quit(); } +}; + /* calls libcurl to encode/decode */ std::string UrlEncode(const std::string &data); std::string UrlDecode(const std::string &data);
--- a/src/core/http.cc Fri Nov 07 07:56:03 2025 -0500 +++ b/src/core/http.cc Fri Nov 07 08:39:24 2025 -0500 @@ -211,4 +211,14 @@ cancelled_ = true; } +void Init() +{ + curl_global_init(CURL_GLOBAL_ALL); +} + +void Quit() +{ + curl_global_cleanup(); +} + } // namespace HTTP
--- a/src/main.cc Fri Nov 07 07:56:03 2025 -0500 +++ b/src/main.cc Fri Nov 07 08:39:24 2025 -0500 @@ -2,6 +2,7 @@ #include "core/anime_db.h" #include "core/date.h" #include "core/session.h" +#include "core/http.h" #include "core/strings.h" #include "gui/window.h" #include "services/anilist.h" @@ -15,6 +16,8 @@ int main(int argc, char **argv) { + HTTP::Initializer http; + QApplication app(argc, argv); app.setApplicationName("minori"); app.setApplicationDisplayName("Minori");
