5#include <condition_variable>
38 using Result = std::expected<Response, Error>;
57 void QueueGet(
const std::string& pUrl,
const std::filesystem::path& pFilepath =
"");
76 void QueueGet(
const std::string& pUrl,
const ResultFunc& pFunc,
const std::filesystem::path& pFilepath =
"");
100 mUserAgent = pUserAgent;
108 [[nodiscard]] std::string
UrlEncode(std::string_view pStr)
const;
111 struct QueueElement {
112 using Variant = std::variant<std::monostate, ResultFunc, ResultPromise>;
116 std::filesystem::path Filepath;
118 QueueElement(std::string pUrl, Variant pCallback, std::filesystem::path pFilepath) : Url(std::move(pUrl)), Callback(std::move(pCallback)), Filepath(std::move(pFilepath)) {}
119 ~QueueElement() =
default;
121 QueueElement(
const QueueElement&) =
delete;
122 QueueElement(QueueElement&& pOther)
noexcept =
default;
123 QueueElement& operator=(
const QueueElement&) =
delete;
124 QueueElement& operator=(QueueElement&& pOther)
noexcept =
default;
127 CURL* mHandle =
nullptr;
128 std::string mLastResponseBuffer;
129 long mLastResponseCode = 0;
131 std::jthread mThread;
132 std::queue<QueueElement> mJobQueue;
133 std::mutex mQueueMutex;
134 std::condition_variable_any mQueueCv;
136 std::string mUserAgent =
"ArcdpsExtension/1.0";
138 static size_t ResponseBufferWriteFunction(
void* pContent,
size_t pSize,
size_t pNMemb,
void* pUserP);
140 void runner(
const std::stop_token& pToken);
Definition SimpleNetworkStack.h:17
SimpleNetworkStack()
Definition SimpleNetworkStack.cpp:5
~SimpleNetworkStack() override
Definition SimpleNetworkStack.cpp:64
std::promise< Result > ResultPromise
Definition SimpleNetworkStack.h:40
void QueueGet(const std::string &pUrl, const std::filesystem::path &pFilepath="")
Definition SimpleNetworkStack.cpp:103
void QueueGet(const std::string &pUrl, ResultPromise pPromise, const std::filesystem::path &pFilepath="")
void SetUserAgent(const std::string &pUserAgent)
Definition SimpleNetworkStack.h:99
std::function< void(const Result &)> ResultFunc
Definition SimpleNetworkStack.h:39
ErrorType
Definition SimpleNetworkStack.h:26
std::string UrlEncode(std::string_view pStr) const
Definition SimpleNetworkStack.cpp:124
std::expected< Response, Error > Result
Definition SimpleNetworkStack.h:38
Definition Singleton.h:47
Definition ArcdpsExtension.h:10
Definition SimpleNetworkStack.h:34
ErrorType Type
Definition SimpleNetworkStack.h:35
std::string Message
Definition SimpleNetworkStack.h:36
Definition SimpleNetworkStack.h:22
long Code
Definition SimpleNetworkStack.h:24
std::string Message
Definition SimpleNetworkStack.h:23