-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add owned::CURL and promote owned::CURLM from launcher
- Loading branch information
1 parent
8e7a21a
commit 2140c30
Showing
2 changed files
with
116 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef OWNED_CURL_H | ||
#define OWNED_CURL_H | ||
|
||
#include <memory> | ||
#include <curl/curl.h> | ||
#include <SDL_log.h> | ||
|
||
// ---------------------------------------------------------------------------- | ||
// CURL | ||
|
||
namespace owned | ||
{ | ||
namespace _deleter | ||
{ | ||
struct CURL | ||
{ | ||
void operator()(::CURL* ptr) | ||
{ | ||
return curl_easy_cleanup(ptr); | ||
} | ||
}; | ||
} | ||
|
||
typedef std::unique_ptr<::CURL, _deleter::CURL> CURL; | ||
|
||
inline CURL curl_easy_init() | ||
{ | ||
return CURL { ::curl_easy_init() }; | ||
} | ||
|
||
inline CURL curl_easy_duphandle(::CURL* d) | ||
{ | ||
return CURL { ::curl_easy_duphandle(d) }; | ||
} | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
// CURLM | ||
|
||
namespace owned | ||
{ | ||
namespace _deleter | ||
{ | ||
struct CURLM | ||
{ | ||
void operator()(::CURLM* ptr) | ||
{ | ||
CURLMcode err; | ||
if (ptr && (err = curl_multi_cleanup(ptr)) != CURLM_OK) | ||
{ | ||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "curl_multi_cleanup: %s", curl_multi_strerror(err)); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
typedef std::unique_ptr<::CURLM, _deleter::CURLM> CURLM; | ||
|
||
inline CURLM curl_multi_init() | ||
{ | ||
return CURLM { ::curl_multi_init() }; | ||
} | ||
} | ||
|
||
[[nodiscard]] // If you don't care about the return value, use .reset() instead. | ||
inline CURLMcode curl_multi_cleanup(owned::CURLM ptr) | ||
{ | ||
return curl_multi_cleanup(ptr.release()); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters