GNURLOPT_SOCKOPTDATA(3)

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

πŸŽ€ NAME πŸŽ€

okay bestie, welcome to the GNURLOPT_SOCKOPTDATA(3) page from the curl_easy_setopt options manual. This one is about CURLOPT_SOCKOPTDATA β€” custom pointer to pass to sockopt callback. That's the whole name, periodt. πŸ’…

✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTDATA, void
*pointer);

πŸ¦‹ DESCRIPTION πŸ¦‹

So you pass a pointer, right? libcurl is gonna leave that pointer completely untouched β€” hands off, no cap β€” and it gets passed as the first argument in the sockopt callback that you set with CURLOPT_SOCKOPTFUNCTION(3). That's it. That's the vibe. 🫢

πŸ“ DEFAULT πŸ“

The default value of this parameter is NULL. So if you don't set it, it's just null, bestie. πŸ™ˆ

🌈 PROTOCOLS 🌈

All β€” every single protocol. no cap. ✨

πŸ”₯ EXAMPLE πŸ”₯

okay here's the cute lil' code moment:

static int sockopt_callback(void *clientp, curl_socket_t curlfd,
                            curlsocktype purpose)
{
  int val = *(int *)clientp;
  setsockopt(curldfd, SOL_SOCKET, SO_RCVBUF, (const char *)&val, sizeof(val));
  return CURL_SOCKOPT_OK;
}

curl = curl_easy_init();
if(curl) {
  int recvbuffersize = 256 * 1024;

  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");

  /* call this function to set options for the socket */
  curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
  curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &recvbuffersize);

  res = curl_easy_perform(curl);

  curl_easy_cleanup(curl);
}

πŸ’œ AVAILABILITY πŸ’œ

Added in 7.16.0. iconic. πŸ‘‘

⭐ RETURN VALUE ⭐

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. Lowkey simple. πŸ’€

🌸 SEE ALSO 🌸

xoxo, ur Unix bestie πŸ’– β€” this page is from libcurl 7.37.0, dated 16 Jun 2014, and it's the GNURLOPT_SOCKOPTDATA(3) manual page. mwah πŸŽ€

πŸ“¦ where this page comes from