curl-cpp
static c++17 wrapper for curl with -fno-exceptions support
|
#include <curl.hpp>
Classes | |
struct | Easy_deleter |
struct | Share_deleter |
struct | Url_deleter |
struct | Version |
Public Types | |
using | malloc_callback_t = void *(*)(std::size_t size) |
using | free_callback_t = void(*)(void *ptr) |
using | realloc_callback_t = void *(*)(void *old_ptr, std::size_t size) |
using | strdup_callback_t = char *(*)(const char *str) |
using | calloc_callback_t = void *(*)(std::size_t nmemb, std::size_t size) |
using | Easy_t = std::unique_ptr< char, Easy_deleter > |
using | Url_t = std::unique_ptr< char, Url_deleter > |
using | Share_t = std::unique_ptr< char, Share_deleter > |
Public Member Functions | |
curl_t (FILE *stderr_stream_arg) noexcept | |
curl_t (FILE *stderr_stream_arg, malloc_callback_t malloc_callback, free_callback_t free_callback, realloc_callback_t realloc_callback, strdup_callback_t strdup_callback, calloc_callback_t calloc_callback) noexcept | |
curl_t (const curl_t &)=delete | |
curl_t (curl_t &&)=delete | |
curl_t & | operator= (const curl_t &)=delete |
curl_t & | operator= (curl_t &&)=delete |
~curl_t () | |
bool | has_compression_support () const noexcept |
bool | has_largefile_support () const noexcept |
bool | has_protocol (const char *protocol) const noexcept |
bool | has_ssl_support () const noexcept |
bool | has_ipv6_support () const noexcept |
bool | has_erase_all_cookies_in_mem_support () const noexcept |
bool | has_erase_all_session_cookies_in_mem_support () const noexcept |
bool | has_flush_cookies_to_jar () const noexcept |
bool | has_reload_cookies_from_file () const noexcept |
bool | has_disable_signal_handling_support () const noexcept |
bool | has_private_ptr_support () const noexcept |
bool | has_readfunc_abort_support () const noexcept |
bool | has_pause_support () const noexcept |
bool | has_header_option_support () const noexcept |
bool | has_set_ip_addr_only_support () const noexcept |
bool | has_redirect_url_support () const noexcept |
bool | has_getinfo_cookie_list_support () const noexcept |
bool | has_buffer_size_tuning_support () const noexcept |
bool | has_buffer_size_growing_support () const noexcept |
bool | has_get_active_socket_support () const noexcept |
auto | create_easy (std::size_t buffer_size=0) noexcept -> Easy_t |
auto | dup_easy (const Easy_t &easy, std::size_t buffer_size=0) noexcept -> Easy_t |
bool | has_CURLU () const noexcept |
auto | create_Url () noexcept -> Url_t |
auto | dup_Url (const Url_t &url) noexcept -> Url_t |
bool | has_multi_poll_support () const noexcept |
bool | has_multi_socket_support () const noexcept |
bool | has_http2_multiplex_support () const noexcept |
bool | has_max_concurrent_stream_support () const noexcept |
auto | create_multi () noexcept -> Ret_except< Multi_t, curl::Exception > |
bool | has_ssl_session_sharing_support () const noexcept |
bool | has_connection_cache_sharing_support () const noexcept |
bool | has_psl_sharing_support () const noexcept |
auto | create_share () noexcept -> Share_t |
Public Attributes | |
FILE * | stderr_stream |
const void *const | version_info |
const Version | version |
bool | disable_signal_handling_v = false |
const char *const | version_str |
There can be multiple instances of this object, as long as during ctor and dtor, there is only one thread in the program.
using curl::curl_t::Easy_t = std::unique_ptr<char, Easy_deleter> |
using curl::curl_t::Url_t = std::unique_ptr<char, Url_deleter> |
using curl::curl_t::Share_t = std::unique_ptr<char, Share_deleter> |
|
noexcept |
Since curl_t is designed to be usable as static variable, it would call errx on error.
It would make sure that Easy_ref_t::get_response_code() is usable before initializing libcurl.
As a side effect, it also make sure that Easy_ref_t::getinfo_sizeof_*, getinfo_transfer_time, getinfo_effective_url must be present.
This is not thread-safe.
Definition at line 70 of file curl.cc.
|
noexcept |
If you are using libcurl from multiple threads or libcurl was built with the threaded resolver option, then the callback functions must be thread safe.
The threaded resolver is a common build option to enable (and in some cases the default) so portable application should make these callback functions thread safe.
All callback arguments must be set to valid function pointers.
libcurl support this from 7.12.0.
If this wasn't supported, you binary probably would have problem during dynamic binding.
NOTE: as a side effect, it also guarantees curl_t::has_buffer_size_tuning_support() to be true.
it would call errx on error.
It would make sure that Easy_ref_t::get_response_code() is usable before initializing libcurl.
As a side effect, it also make sure that Easy_ref_t::getinfo_sizeof_*, getinfo_transfer_time, getinfo_effective_url must be present.
This is not thread-safe.
Definition at line 105 of file curl.cc.
curl::curl_t::~curl_t | ( | ) |
Destructor is not thread safe.
You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running.
This doesn't just mean no other thread that is using libcurl. Because curl_global_cleanup calls functions of other libraries that are similarly thread unsafe, it could conflict with any other thread that uses these other libraries.
This dtor does not block waiting for any libcurl-created threads to terminate (such as threads used for name resolving).
If a module containing libcurl is dynamically unloaded while libcurl-created threads are still running then your program may crash or other corruption may occur.
We recommend you do not run libcurl from any module that may be unloaded dynamically.
This behavior may be addressed in the future.
|
noexcept |
|
noexcept |
buffer_size | size of receiver buffer. This buffer size is by default CURL_MAX_WRITE_SIZE (16kB). The maximum buffer size allowed to be set is CURL_MAX_READ_SIZE (512kB). The minimum buffer size allowed to be set is 1024. Set to 0 to use default value. This param is just treated as a request, not an order. |
If stderr_stream set to non-NULL, verbose info will be printed there. If disable_signal_handling_v is set, signal handling is disabled.
As long as stderr_stream and disable_signal_handling_v is not modified when create_easy is called, this function is thread-safe.
Definition at line 20 of file curl_easy.cc.
easy | must not be nullptr |
buffer_size | same as create_easy |
All string passed into curl_easy_setopt using char* will be pointed by the new hanlde as well. Thus they must be kept around until both handles is destroyed.
The new handle will not inherit any state information, no connections, no SSL sessions and no cookies.
It also will not inherit any share object states or options (it will be made as if CURLOPT_SHARE was set to NULL).
If stderr_stream set to non-nullptr, verbose info will be printed there. If disable_signal_handling_v is set, signal handling is disabled.
easy must not be used in any way during this function call.
Definition at line 43 of file curl_easy.cc.
|
noexcept |
|
noexcept |
Since Url_ref_t doesn't have any other data except pointer to CURLU itself, returning std::unique_ptr instead of an object like Easy_t would make it easier to manage it in custom ways like std::shared_ptr.
It is thread-safe.
Definition at line 11 of file curl_url.cc.
url | != nullptr |
url must not be used during this function call.
Definition at line 15 of file curl_url.cc.
|
noexcept |
|
noexcept |
|
noexcept |
FILE* curl::curl_t::stderr_stream |
const void* const curl::curl_t::version_info |
const Version curl::curl_t::version |
bool curl::curl_t::disable_signal_handling_v = false |
disable_signal_handling_v is placed here to compress alignment requirement for bool and Version.
If your libcurl uses standard name resolver, disable signal handling might cause timeout to never occur during name resolution.
Disable signal handling makes libcurl NOT ask the system to ignore SIGPIPE signals, which otherwise are sent by the system when trying to send data to a socket which is closed in the other end.
libcurl makes an effort to never cause such SIGPIPEs to trigger, but some operating systems have no way to avoid them and even on those that have there are some corner cases when they may still happen, contrary to our desire.
In addition, using CURLAUTH_NTLM_WB authentication could cause a SIGCHLD signal to be raised.
Modifing this would only affect Easy_t handle created after the modification.
const char* const curl::curl_t::version_str |