CURLOPT_XFERINFOFUNCTION.3 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_XFERINFOFUNCTION 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_XFERINFOFUNCTION \- progress meter callback
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. int progress_callback(void *clientp,
  30. curl_off_t dltotal,
  31. curl_off_t dlnow,
  32. curl_off_t ultotal,
  33. curl_off_t ulnow);
  34. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XFERINFOFUNCTION,
  35. progress_callback);
  36. .fi
  37. .SH DESCRIPTION
  38. Pass a pointer to your callback function, which should match the prototype
  39. shown above.
  40. This function gets called by libcurl instead of its internal equivalent with a
  41. frequent interval. While data is being transferred it will be called
  42. frequently, and during slow periods like when nothing is being transferred it
  43. can slow down to about one call per second.
  44. \fIclientp\fP is the pointer set with \fICURLOPT_XFERINFODATA(3)\fP, it is not
  45. used by libcurl but is only passed along from the application to the callback.
  46. The callback gets told how much data libcurl will transfer and has
  47. transferred, in number of bytes. \fIdltotal\fP is the total number of bytes
  48. libcurl expects to download in this transfer. \fIdlnow\fP is the number of
  49. bytes downloaded so far. \fIultotal\fP is the total number of bytes libcurl
  50. expects to upload in this transfer. \fIulnow\fP is the number of bytes
  51. uploaded so far.
  52. Unknown/unused argument values passed to the callback will be set to zero
  53. (like if you only download data, the upload size will remain 0). Many times
  54. the callback will be called one or more times first, before it knows the data
  55. sizes so a program must be made to handle that.
  56. If your callback function returns CURL_PROGRESSFUNC_CONTINUE it will cause
  57. libcurl to continue executing the default progress function.
  58. Returning any other non-zero value from this callback will cause libcurl to
  59. abort the transfer and return \fICURLE_ABORTED_BY_CALLBACK\fP.
  60. If you transfer data with the multi interface, this function will not be
  61. called during periods of idleness unless you call the appropriate libcurl
  62. function that performs transfers.
  63. \fICURLOPT_NOPROGRESS(3)\fP must be set to 0 to make this function actually
  64. get called.
  65. .SH DEFAULT
  66. By default, libcurl has an internal progress meter. That is rarely wanted by
  67. users.
  68. .SH PROTOCOLS
  69. All
  70. .SH EXAMPLE
  71. .nf
  72. struct progress {
  73. char *private;
  74. size_t size;
  75. };
  76. static size_t progress_callback(void *clientp,
  77. curl_off_t dltotal,
  78. curl_off_t dlnow,
  79. curl_off_t ultotal,
  80. curl_off_t ulnow)
  81. {
  82. struct progress *memory = (struct progress *)clientp;
  83. /* use the values */
  84. return 0; /* all is good */
  85. }
  86. struct progress data;
  87. /* pass struct to callback */
  88. curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &data);
  89. curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
  90. .fi
  91. .SH AVAILABILITY
  92. Added in 7.32.0. This callback replaces \fICURLOPT_PROGRESSFUNCTION(3)\fP
  93. .SH RETURN VALUE
  94. Returns CURLE_OK.
  95. .SH "SEE ALSO"
  96. .BR CURLOPT_XFERINFODATA "(3), " CURLOPT_NOPROGRESS "(3), "