18 #ifndef KVIKIO_LIBCURL_FOUND
20 "cannot include the remote IO API, please build KvikIO with libcurl (-DKvikIO_REMOTE_SUPPORT=ON)"
30 #include <curl/curl.h>
32 #include <kvikio/error.hpp>
56 using UniqueHandlePtr = std::unique_ptr<CURL, std::function<decltype(curl_easy_cleanup)>>;
61 std::vector<UniqueHandlePtr> _free_curl_handles{};
93 char _errbuf[CURL_ERROR_SIZE];
94 LibCurl::UniqueHandlePtr _handle;
106 CurlHandle(LibCurl::UniqueHandlePtr
handle, std::string source_file, std::string source_line);
130 template <typename VAL>
131 void setopt(CURLoption option, VAL value)
133 CURLcode err = curl_easy_setopt(
handle(), option, value);
134 if (err != CURLE_OK) {
135 std::stringstream ss;
136 ss <<
"curl_easy_setopt() error "
137 <<
"(" << curl_easy_strerror(err) <<
")";
157 template <
typename OUTPUT>
160 CURLcode err = curl_easy_getinfo(
handle(), info, output);
161 if (err != CURLE_OK) {
162 std::stringstream ss;
163 ss <<
"curl_easy_getinfo() error "
164 <<
"(" << curl_easy_strerror(err) <<
")";
185 __attribute__((noinline))
inline std::string fix_conda_file_path_hack(std::string filename)
187 if (filename.data() !=
nullptr) {
return std::string{filename.data()}; }
188 return std::string{};
197 #define create_curl_handle() \
198 kvikio::CurlHandle(kvikio::LibCurl::instance().get_handle(), \
199 kvikio::detail::fix_conda_file_path_hack(__FILE__), \
200 KVIKIO_STRINGIFY(__LINE__))
Representation of a curl easy handle pointer and its operations.
void setopt(CURLoption option, VAL value)
Set option for the curl handle.
CurlHandle(LibCurl::UniqueHandlePtr handle, std::string source_file, std::string source_line)
Construct a new curl handle.
void getinfo(CURLINFO info, OUTPUT *output)
Extract information from a curl handle.
void perform()
Perform a blocking network transfer using previously set options.
CURL * handle() noexcept
Get the underlying curl easy handle pointer.
Singleton class to initialize and cleanup the global state of libcurl.
UniqueHandlePtr get_free_handle()
Returns a free curl handle if available.
void retain_handle(UniqueHandlePtr handle)
Retain a curl handle for later use.
UniqueHandlePtr get_handle()
Returns a curl handle, create a new handle if none is available.
#define KVIKIO_FAIL(...)
Indicates that an erroneous code path has been taken.