GNURLOPT_R...T_FUNCTION(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… 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 πŸ‘‘


✨ 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