Mercurial > minori
comparison include/core/http.h @ 390:2d3e10319112
http: optimize HTTP request thread
we don't need a mutex at all, in fact all we need is an atomic
boolean to signify whether the thread is cancelled.
curl options are now for the most part handled by a separate
function to keep them in sync between non-threaded and threaded
implementations
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 07 Nov 2025 07:08:57 -0500 |
| parents | 1e5d922fe82b |
| children | 963047512d34 |
comparison
equal
deleted
inserted
replaced
| 389:1e5d922fe82b | 390:2d3e10319112 |
|---|---|
| 5 #include <QThread> | 5 #include <QThread> |
| 6 | 6 |
| 7 #include <mutex> | 7 #include <mutex> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <atomic> | |
| 10 | 11 |
| 11 namespace HTTP { | 12 namespace HTTP { |
| 12 | 13 |
| 13 /* calls libcurl to encode/decode */ | 14 /* calls libcurl to encode/decode */ |
| 14 std::string UrlEncode(const std::string &data); | 15 std::string UrlEncode(const std::string &data); |
| 50 | 51 |
| 51 std::string url_; | 52 std::string url_; |
| 52 std::string data_; | 53 std::string data_; |
| 53 std::vector<std::string> headers_; | 54 std::vector<std::string> headers_; |
| 54 Type type_; | 55 Type type_; |
| 56 void *curl_; | |
| 55 | 57 |
| 56 /* these are passed to the write callback */ | 58 /* these are passed to the write callback */ |
| 57 QByteArray array_; | 59 QByteArray array_; |
| 58 bool cancelled_ = false; | 60 std::atomic<bool> cancelled_ = false; |
| 59 | |
| 60 /* don't fuck this up */ | |
| 61 std::mutex callback_data_mutex_; | |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 } // namespace HTTP | 63 } // namespace HTTP |
| 65 | 64 |
| 66 #endif // MINORI_CORE_HTTP_H_ | 65 #endif // MINORI_CORE_HTTP_H_ |
