CURLOPT_SOCKOPTDATA(3)

CURLOPT_SOCKOPTDATA3

Pointer to pass to sockopt callback

Usage

#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTDATA, void *pointer);

Overview

Pass a pointer that is untouched by libcurl and passed as the first argument in the sockopt callback set with CURLOPT_SOCKOPTFUNCTION(3).

Default

NULL

Protocols

This functionality affects all supported protocols

Examples

static int sockopt_callback(void *clientp, curl_socket_t curlfd,
                            curlsocktype purpose)
{
  int val = *(int *)clientp;
  setsockopt((int)curlfd, SOL_SOCKET, SO_RCVBUF,
             (const char *)&val, sizeof(val));
  return CURL_SOCKOPT_OK;
}
int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    int recvbuffersize = 256 * 1024;
    curl_easy_setopt(curl, CURLOPT_URL, "https://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);
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

Return value

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.

Releases

7 releases since Debian 8 (Jessie); the text changed 6 times.

  1. 8
  2. 9
  3. 10
  4. 11
  5. 12
  6. 13
  7. Arch

Availability

Added in curl 7.16.0

From curl 8.23.0-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.