5#include <condition_variable>
44 using Result = std::expected<Response, Error>;
63 void QueueGet(
const std::string& pUrl,
const std::filesystem::path& pFilepath =
"");
82 void QueueGet(
const std::string& pUrl,
const ResultFunc& pFunc,
const std::filesystem::path& pFilepath =
"");
106 mUserAgent = pUserAgent;
114 [[nodiscard]] std::string
UrlEncode(std::string_view pStr)
const;
117 struct QueueElement {
118 using Variant = std::variant<std::monostate, ResultFunc, ResultPromise>;
122 std::filesystem::path Filepath;
124 QueueElement(std::string pUrl, Variant pCallback, std::filesystem::path pFilepath) : Url(std::move(pUrl)), Callback(std::move(pCallback)), Filepath(std::move(pFilepath)) {}
125 ~QueueElement() =
default;
127 QueueElement(
const QueueElement&) =
delete;
128 QueueElement(QueueElement&& pOther)
noexcept =
default;
129 QueueElement& operator=(
const QueueElement&) =
delete;
130 QueueElement& operator=(QueueElement&& pOther)
noexcept =
default;
133 CURL* mHandle =
nullptr;
134 std::string mLastResponseBuffer;
135 long mLastResponseCode = 0;
137 std::jthread mThread;
138 std::queue<QueueElement> mJobQueue;
139 std::mutex mQueueMutex;
140 std::condition_variable_any mQueueCv;
142 std::string mUserAgent =
"ArcdpsExtension/1.0";
144 static size_t ResponseBufferWriteFunction(
void* pContent,
size_t pSize,
size_t pNMemb,
void* pUserP);
146 void runner(
const std::stop_token& pToken);
Definition SimpleNetworkStack.h:23
SimpleNetworkStack()
Definition SimpleNetworkStack.cpp:7
~SimpleNetworkStack() override
Definition SimpleNetworkStack.cpp:72
std::promise< Result > ResultPromise
Definition SimpleNetworkStack.h:46
void QueueGet(const std::string &pUrl, const std::filesystem::path &pFilepath="")
Definition SimpleNetworkStack.cpp:111
void QueueGet(const std::string &pUrl, ResultPromise pPromise, const std::filesystem::path &pFilepath="")
void SetUserAgent(const std::string &pUserAgent)
Definition SimpleNetworkStack.h:105
std::function< void(const Result &)> ResultFunc
Definition SimpleNetworkStack.h:45
ErrorType
Definition SimpleNetworkStack.h:32
std::string UrlEncode(std::string_view pStr) const
Definition SimpleNetworkStack.cpp:132
std::expected< Response, Error > Result
Definition SimpleNetworkStack.h:44
Definition Singleton.h:48
Definition ArcdpsExtension.h:10
Definition SimpleNetworkStack.h:40
ErrorType Type
Definition SimpleNetworkStack.h:41
std::string Message
Definition SimpleNetworkStack.h:42
Definition SimpleNetworkStack.h:28
long Code
Definition SimpleNetworkStack.h:30
std::string Message
Definition SimpleNetworkStack.h:29