1CURLOPT_XFERINFOFUNCTION(3) libcurl CURLOPT_XFERINFOFUNCTION(3)
2
3
4
6 CURLOPT_XFERINFOFUNCTION - progress meter callback
7
9 #include <curl/curl.h>
10
11 int progress_callback(void *clientp,
12 curl_off_t dltotal,
13 curl_off_t dlnow,
14 curl_off_t ultotal,
15 curl_off_t ulnow);
16
17 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XFERINFOFUNCTION,
18 progress_callback);
19
21 Pass a pointer to your callback function, which should match the proto‐
22 type shown above.
23
24 This function gets called by libcurl instead of its internal equivalent
25 with a frequent interval. While data is being transferred it will be
26 called frequently, and during slow periods like when nothing is being
27 transferred it can slow down to about one call per second.
28
29 clientp is the pointer set with CURLOPT_XFERINFODATA(3), it is not used
30 by libcurl but is only passed along from the application to the call‐
31 back.
32
33 The callback gets told how much data libcurl will transfer and has
34 transferred, in number of bytes. dltotal is the total number of bytes
35 libcurl expects to download in this transfer. dlnow is the number of
36 bytes downloaded so far. ultotal is the total number of bytes libcurl
37 expects to upload in this transfer. ulnow is the number of bytes up‐
38 loaded so far.
39
40 Unknown/unused argument values passed to the callback will be set to
41 zero (like if you only download data, the upload size will remain 0).
42 Many times the callback will be called one or more times first, before
43 it knows the data sizes so a program must be made to handle that.
44
45 If your callback function returns CURL_PROGRESSFUNC_CONTINUE it will
46 cause libcurl to continue executing the default progress function.
47
48 Returning any other non-zero value from this callback will cause
49 libcurl to abort the transfer and return CURLE_ABORTED_BY_CALLBACK.
50
51 If you transfer data with the multi interface, this function will not
52 be called during periods of idleness unless you call the appropriate
53 libcurl function that performs transfers.
54
55 CURLOPT_NOPROGRESS(3) must be set to 0 to make this function actually
56 get called.
57
59 By default, libcurl has an internal progress meter. That is rarely
60 wanted by users.
61
63 All
64
66 struct progress {
67 char *private;
68 size_t size;
69 };
70
71 static size_t progress_callback(void *clientp,
72 curl_off_t dltotal,
73 curl_off_t dlnow,
74 curl_off_t ultotal,
75 curl_off_t ulnow)
76 {
77 struct progress *memory = (struct progress *)clientp;
78
79 /* use the values */
80
81 return 0; /* all is good */
82 }
83
84 struct progress data;
85
86 /* pass struct to callback */
87 curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &data);
88
89 curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
90
92 Added in 7.32.0. This callback replaces CURLOPT_PROGRESSFUNCTION(3)
93
95 Returns CURLE_OK.
96
98 CURLOPT_XFERINFODATA(3), CURLOPT_NOPROGRESS(3),
99
100
101
102ibcurl 8.2.1 April 26, 2023 CURLOPT_XFERINFOFUNCTION(3)