WIP: CURL/request implementation.

This commit is contained in:
2024-09-11 08:57:43 +02:00
parent 4e93898a56
commit 92d7b5552f
3 changed files with 209 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
#include "./request.hpp"
#include <mutex>
#include "./curl_wrappers.hpp"
namespace mijin
{
namespace
{
bool gCurlInited = false;
std::mutex gCurlInitMutex;
class CURLGuard
{
public:
~CURLGuard() MIJIN_NOEXCEPT
{
if (gCurlInited)
{
curl_global_cleanup();
}
}
} gCURLGuard [[maybe_unused]];
bool initCURL() MIJIN_NOEXCEPT
{
if (gCurlInited)
{
return true;
}
const std::unique_lock initLock(gCurlInitMutex);
if (gCurlInited)
{
return true;
}
gCurlInited = (curl_global_init(0) == CURLE_OK);
return gCurlInited;
}
}
Task<StreamResult<HTTPResponse>> c_request(const URL& url, HTTPRequest request) MIJIN_NOEXCEPT
{
(void) url;
(void) request;
if (!initCURL())
{
co_return StreamError::UNKNOWN_ERROR;
}
curl::CurlEasy easy;
if (!easy.init())
{
co_return StreamError::UNKNOWN_ERROR;
}
easy.setURL(url);
co_return StreamError::UNKNOWN_ERROR;
}
} // namespace mijin