CURLOPT_SOCKOPTDATA.3 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. .\" generated by cd2nroff 0.1 from CURLOPT_SOCKOPTDATA.md
  2. .TH CURLOPT_SOCKOPTDATA 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_SOCKOPTDATA \- pointer to pass to sockopt callback
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTDATA, void *pointer);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a \fIpointer\fP that is untouched by libcurl and passed as the first
  12. argument in the sockopt callback set with \fICURLOPT_SOCKOPTFUNCTION(3)\fP.
  13. .SH DEFAULT
  14. NULL
  15. .SH PROTOCOLS
  16. This functionality affects all supported protocols
  17. .SH EXAMPLE
  18. .nf
  19. static int sockopt_callback(void *clientp, curl_socket_t curlfd,
  20. curlsocktype purpose)
  21. {
  22. int val = *(int *)clientp;
  23. setsockopt((int)curlfd, SOL_SOCKET, SO_RCVBUF,
  24. (const char *)&val, sizeof(val));
  25. return CURL_SOCKOPT_OK;
  26. }
  27. int main(void)
  28. {
  29. CURL *curl = curl_easy_init();
  30. if(curl) {
  31. CURLcode res;
  32. int recvbuffersize = 256 * 1024;
  33. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  34. /* call this function to set options for the socket */
  35. curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
  36. curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &recvbuffersize);
  37. res = curl_easy_perform(curl);
  38. curl_easy_cleanup(curl);
  39. }
  40. }
  41. .fi
  42. .SH AVAILABILITY
  43. Added in curl 7.16.0
  44. .SH RETURN VALUE
  45. Returns \fICURLE_OK\fP if the option is supported, and \fICURLE_UNKNOWN_OPTION\fP if not.
  46. .SH SEE ALSO
  47. .BR CURLOPT_OPENSOCKETFUNCTION (3),
  48. .BR CURLOPT_SOCKOPTFUNCTION (3)