CURLOPT_CLOSESOCKETFUNCTION.3 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. .\" generated by cd2nroff 0.1 from CURLOPT_CLOSESOCKETFUNCTION.md
  2. .TH CURLOPT_CLOSESOCKETFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_CLOSESOCKETFUNCTION \- callback to socket close replacement
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. int closesocket_callback(void *clientp, curl_socket_t item);
  9. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CLOSESOCKETFUNCTION,
  10. closesocket_callback);
  11. .fi
  12. .SH DESCRIPTION
  13. Pass a pointer to your callback function, which should match the prototype
  14. shown above.
  15. This callback function gets called by libcurl instead of the \fIclose(3)\fP or
  16. \fIclosesocket(3)\fP call when sockets are closed (not for any other file
  17. descriptors). This is pretty much the reverse to the
  18. \fICURLOPT_OPENSOCKETFUNCTION(3)\fP option. Return 0 to signal success and 1
  19. if there was an error.
  20. The \fIclientp\fP pointer is set with
  21. \fICURLOPT_CLOSESOCKETDATA(3)\fP. \fIitem\fP is the socket libcurl wants to be
  22. closed.
  23. .SH DEFAULT
  24. Use the standard socket close function.
  25. .SH PROTOCOLS
  26. This functionality affects all supported protocols
  27. .SH EXAMPLE
  28. .nf
  29. struct priv {
  30. void *custom;
  31. };
  32. static int closesocket(void *clientp, curl_socket_t item)
  33. {
  34. struct priv *my = clientp;
  35. printf("our ptr: %p\\n", my->custom);
  36. printf("libcurl wants to close %d now\\n", (int)item);
  37. return 0;
  38. }
  39. int main(void)
  40. {
  41. struct priv myown;
  42. CURL *curl = curl_easy_init();
  43. /* call this function to close sockets */
  44. curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
  45. curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown);
  46. curl_easy_perform(curl);
  47. curl_easy_cleanup(curl);
  48. }
  49. .fi
  50. .SH AVAILABILITY
  51. Added in curl 7.21.7
  52. .SH RETURN VALUE
  53. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  54. .SH SEE ALSO
  55. .BR CURLOPT_CLOSESOCKETDATA (3),
  56. .BR CURLOPT_OPENSOCKETFUNCTION (3)