GNURLOPT_R...T_FUNCTION(3)
π GNURLOPT_R...T_FUNCTION β like, the resolver-start callback one, bestie
Okay so this page lives in the curl_easy_setopt options manual section (that's the manual name, iykyk), and it's all about CURLOPT_RESOLVER_START_FUNCTION. Buckle up, it's actually iconic.
β¨ NAME β¨
CURLOPT_RESOLVER_START_FUNCTION β set a callback that gets called before a new resolve request is started π
πΈ SYNOPSIS πΈ
#include <gnurl/curl.h>
int resolver_start_cb(void *resolver_state, void *reserved, void *userdata);
CURLcode curl_easy_setopt(CURL *handle,
CURLOPT_RESOLVER_START_FUNCTION,
resolver_start_cb);
π¦ DESCRIPTION π¦
So you pass a pointer to your callback function, and it should match the prototype shown above, fr fr. No cap.
This callback gets called by libcurl like every single time before a new resolve request is started. Main character energy β it's there before anything else goes down. π
resolver_state points to a backend-specific resolver state. Right now (ngl, currently) only the ares resolver backend even has a resolver state. You can use it to set up whatever option you want on the ares channel before it's used β for example, setting up socket callback options. Slay.
reserved is reserved. That's it. That's the whole vibe. π Literally reserved.
userdata is the user pointer you set with the CURLOPT_RESOLVER_START_DATA(3) option. That's your lil' stuff, your data, your moment. β¨
β οΈ The callback must return 0 on success. Returning a non-zero value will cause the resolve to fail. So likeβ¦ don't do that unless you actually want it to fail, bestie. π
π DEFAULT π
NULL (No callback) β nothing, nada, nobody's home. π«Ά
π PROTOCOLS π
All. Every single one. Periodt. π
π EXAMPLE π
static int resolver_start_cb(void *resolver_state, void *reserved,
void *userdata)
{
(void)reserved;
printf("Received resolver_state=%p userdata=%p\n",
resolver_state, userdata);
return 0;
}
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_RESOLVER_START_FUNCTION, resolver_start_cb);
curl_easy_setopt(curl, CURLOPT_RESOLVER_START_DATA, curl);
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
Look at her go. Setting the function, setting the data to curl itself, setting the URL, performing the whole entire thing, cleaning up after herself. Responsible queen behavior. π
β AVAILABILITY β
Added in 7.59.0 β so she's been around, she's established, she ate. π₯
π RETURN VALUE π
Returns CURLE_OK. That's it. That's the return value. Simple, clean, no drama. π
π SEE ALSO π
CURLOPT_RESOLVER_START_DATA(3)β the other half of this duo, go read it π«Ά
β¨ mwah β¨ that's the page, bestie. This cutie is from libcurl 7.59.0, dated 14 Feb 2018, and it's filed under GNURLOPT_R...T_FUNCTION(3) in the curl_easy_setopt options manual β go forth and resolve responsibly ππ¦π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms