1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_PROGRESSFUNCTION
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_NOPROGRESS (3)
9  - CURLOPT_VERBOSE (3)
10  - CURLOPT_XFERINFOFUNCTION (3)
11---
12
13# NAME
14
15CURLOPT_PROGRESSFUNCTION - progress meter callback
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22int progress_callback(void *clientp,
23                      double dltotal,
24                      double dlnow,
25                      double ultotal,
26                      double ulnow);
27
28CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROGRESSFUNCTION,
29                          progress_callback);
30~~~
31
32# DESCRIPTION
33
34Pass a pointer to your callback function, which should match the prototype
35shown above.
36
37This option is deprecated and we encourage users to use the
38newer CURLOPT_XFERINFOFUNCTION(3) instead, if you can.
39
40This function gets called by libcurl instead of its internal equivalent with a
41frequent interval. While data is being transferred it is invoked frequently,
42and during slow periods like when nothing is being transferred it can slow
43down to about one call per second.
44
45*clientp* is the pointer set with CURLOPT_PROGRESSDATA(3), it is not
46used by libcurl but is only passed along from the application to the callback.
47
48The callback gets told how much data libcurl is about to transfer and has
49transferred, in number of bytes. *dltotal* is the total number of bytes
50libcurl expects to download in this transfer. *dlnow* is the number of
51bytes downloaded so far. *ultotal* is the total number of bytes libcurl
52expects to upload in this transfer. *ulnow* is the number of bytes
53uploaded so far.
54
55Unknown/unused argument values passed to the callback are be set to zero (like
56if you only download data, the upload size remains 0). Many times the callback
57is called one or more times first, before it knows the data sizes so a program
58must be made to handle that.
59
60If your callback function returns CURL_PROGRESSFUNC_CONTINUE it causes libcurl
61to continue executing the default progress function.
62
63Returning any other non-zero value from this callback makes libcurl abort the
64transfer and return *CURLE_ABORTED_BY_CALLBACK*.
65
66If you transfer data with the multi interface, this function is not called
67during periods of idleness unless you call the appropriate libcurl function
68that performs transfers.
69
70CURLOPT_NOPROGRESS(3) must be set to 0 to make this function actually
71get called.
72
73# DEFAULT
74
75By default, libcurl has an internal progress meter. That is rarely wanted by
76users.
77
78# PROTOCOLS
79
80All
81
82# EXAMPLE
83
84~~~c
85struct progress {
86  char *private;
87  size_t size;
88};
89
90static size_t progress_callback(void *clientp,
91                                double dltotal,
92                                double dlnow,
93                                double ultotal,
94                                double ulnow)
95{
96  struct progress *memory = clientp;
97  printf("private: %p\n", memory->private);
98
99  /* use the values */
100
101  return 0; /* all is good */
102}
103
104int main(void)
105{
106  struct progress data;
107
108  CURL *curl = curl_easy_init();
109  if(curl) {
110    /* pass struct to callback  */
111    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
112    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
113
114    curl_easy_perform(curl);
115  }
116}
117~~~
118
119# AVAILABILITY
120
121Deprecated since 7.32.0.
122
123# RETURN VALUE
124
125Returns CURLE_OK.
126