CURLOPT_XFERINFOFUNCTION.3 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. .\" generated by cd2nroff 0.1 from CURLOPT_XFERINFOFUNCTION.md
  2. .TH CURLOPT_XFERINFOFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_XFERINFOFUNCTION \- progress meter callback
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. int progress_callback(void *clientp,
  9. curl_off_t dltotal,
  10. curl_off_t dlnow,
  11. curl_off_t ultotal,
  12. curl_off_t ulnow);
  13. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XFERINFOFUNCTION,
  14. progress_callback);
  15. .fi
  16. .SH DESCRIPTION
  17. Pass a pointer to your callback function, which should match the prototype
  18. shown above.
  19. This function gets called by libcurl instead of its internal equivalent with a
  20. frequent interval. While data is being transferred it gets called frequently,
  21. and during slow periods like when nothing is being transferred it can slow
  22. down to about one call per second.
  23. \fIclientp\fP is the pointer set with \fICURLOPT_XFERINFODATA(3)\fP, it is not
  24. used by libcurl but is only passed along from the application to the callback.
  25. The callback gets told how much data libcurl is about to transfer and has
  26. already transferred, in number of bytes. \fIdltotal\fP is the total number of
  27. bytes libcurl expects to download in this transfer. \fIdlnow\fP is the number
  28. of bytes downloaded so far. \fIultotal\fP is the total number of bytes libcurl
  29. expects to upload in this transfer. \fIulnow\fP is the number of bytes
  30. uploaded so far.
  31. Unknown/unused argument values passed to the callback are set to zero (like if
  32. you only download data, the upload size remains 0). Many times the callback is
  33. called one or more times first, before it knows the data sizes so a program
  34. must be made to handle that.
  35. If your callback function returns CURL_PROGRESSFUNC_CONTINUE it makes libcurl
  36. to continue executing the default progress function.
  37. Returning any other non\-zero value from this callback makes libcurl abort the
  38. transfer and return \fICURLE_ABORTED_BY_CALLBACK\fP.
  39. If you transfer data with the multi interface, this function is not called
  40. during periods of idleness unless you call the appropriate libcurl function
  41. that performs transfers.
  42. \fICURLOPT_NOPROGRESS(3)\fP must be set to 0 to make this function actually
  43. get called.
  44. .SH DEFAULT
  45. NULL \- use the internal progress meter. That is rarely wanted by users.
  46. .SH PROTOCOLS
  47. This functionality affects all supported protocols
  48. .SH EXAMPLE
  49. .nf
  50. struct progress {
  51. char *private;
  52. size_t size;
  53. };
  54. static size_t progress_callback(void *clientp,
  55. curl_off_t dltotal,
  56. curl_off_t dlnow,
  57. curl_off_t ultotal,
  58. curl_off_t ulnow)
  59. {
  60. struct progress *memory = clientp;
  61. printf("my ptr: %p\\n", memory->private);
  62. /* use the values */
  63. return 0; /* all is good */
  64. }
  65. int main(void)
  66. {
  67. CURL *curl = curl_easy_init();
  68. if(curl) {
  69. struct progress data;
  70. /* pass struct to callback */
  71. curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &data);
  72. /* enable progress callback getting called */
  73. curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
  74. curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
  75. }
  76. }
  77. .fi
  78. .SH AVAILABILITY
  79. Added in curl 7.32.0
  80. .SH RETURN VALUE
  81. Returns CURLE_OK.
  82. .SH SEE ALSO
  83. .BR CURLOPT_NOPROGRESS (3),
  84. .BR CURLOPT_XFERINFODATA (3)