CURLOPT_PROGRESSFUNCTION.3 3.4 KB

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