Artifactspublic-v0

curl

master
ply4 git calls133 ms288 KiB1 cachedprotocol v2
126 lines3.4 KiBRaw

NAME

CURLOPT_XFERINFOFUNCTION - progress meter callback

SYNOPSIS

c
#include <curl/curl.h>

int progress_callback(void *clientp,
                      curl_off_t dltotal,
                      curl_off_t dlnow,
                      curl_off_t ultotal,
                      curl_off_t ulnow);

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XFERINFOFUNCTION,
                          progress_callback);

DESCRIPTION

Pass a pointer to your callback function, which should match the prototype shown above.

This function gets called by libcurl instead of its internal equivalent with a frequent interval. While data is being transferred it gets called frequently, and during slow periods like when nothing is being transferred it can slow down to about one call per second.

clientp is the pointer set with CURLOPT_XFERINFODATA(3), it is not used by libcurl but is only passed along from the application to the callback.

The callback gets told how much data libcurl is about to transfer and has already transferred, in number of bytes. dltotal is the total number of bytes libcurl expects to download in this transfer. dlnow is the number of bytes downloaded so far. ultotal is the total number of bytes libcurl expects to upload in this transfer. ulnow is the number of bytes uploaded so far.

Unknown/unused argument values passed to the callback are set to zero (like if you only download data, the upload size remains 0). Many times the callback is called one or more times first, before it knows the data sizes so a program must be made to handle that.

Return zero from the callback if everything is fine.

Return 1 from this callback to make libcurl abort the transfer and return CURLE_ABORTED_BY_CALLBACK.

If your callback function returns CURL_PROGRESSFUNC_CONTINUE it makes libcurl to continue executing the default progress function.

If you transfer data with the multi interface, this function is not called during periods of idleness unless you call the appropriate libcurl function that performs transfers.

CURLOPT_NOPROGRESS(3) must be set to 0 to make this function actually get called.

DEFAULT

NULL - use the internal progress meter. That is rarely wanted by users.

%PROTOCOLS%

EXAMPLE

c
struct progress {
  char *private_data;
  size_t size;
};

static int xferinfo_callback(void *clientp,
                             curl_off_t dltotal,
                             curl_off_t dlnow,
                             curl_off_t ultotal,
                             curl_off_t ulnow)
{
  struct progress *memory = clientp;
  printf("my ptr: %p\n", (void *)memory->private_data);

  /* use the values */

  return 0; /* all is good */
}

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    struct progress data;

    /* pass struct to callback */
    curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &data);

    /* enable progress callback getting called */
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);

    curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo_callback);
  }
}

%AVAILABILITY%

RETURN VALUE

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3).

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_XFERINFOFUNCTION
5Section: 3
6Source: libcurl
7See-also:
8 - CURLOPT_NOPROGRESS (3)
9 - CURLOPT_XFERINFODATA (3)
10Protocol:
11 - All
12Added-in: 7.32.0
13---
15# NAME
17CURLOPT_XFERINFOFUNCTION - progress meter callback
19# SYNOPSIS
21~~~c
22#include <curl/curl.h>
24int progress_callback(void *clientp,
25 curl_off_t dltotal,
26 curl_off_t dlnow,
27 curl_off_t ultotal,
28 curl_off_t ulnow);
30CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XFERINFOFUNCTION,
31 progress_callback);
32~~~
34# DESCRIPTION
36Pass a pointer to your callback function, which should match the prototype
37shown above.
39This function gets called by libcurl instead of its internal equivalent with a
40frequent interval. While data is being transferred it gets called frequently,
41and during slow periods like when nothing is being transferred it can slow
42down to about one call per second.
44*clientp* is the pointer set with CURLOPT_XFERINFODATA(3), it is not
45used by libcurl but is only passed along from the application to the callback.
47The callback gets told how much data libcurl is about to transfer and has
48already transferred, in number of bytes. *dltotal* is the total number of
49bytes libcurl expects to download in this transfer. *dlnow* is the number
50of bytes downloaded so far. *ultotal* is the total number of bytes libcurl
51expects to upload in this transfer. *ulnow* is the number of bytes
52uploaded so far.
54Unknown/unused argument values passed to the callback are set to zero (like if
55you only download data, the upload size remains 0). Many times the callback is
56called one or more times first, before it knows the data sizes so a program
57must be made to handle that.
59Return zero from the callback if everything is fine.
61Return 1 from this callback to make libcurl abort the transfer and return
62*CURLE_ABORTED_BY_CALLBACK*.
64If your callback function returns CURL_PROGRESSFUNC_CONTINUE it makes libcurl
65to continue executing the default progress function.
67If you transfer data with the multi interface, this function is not called
68during periods of idleness unless you call the appropriate libcurl function
69that performs transfers.
71CURLOPT_NOPROGRESS(3) must be set to 0 to make this function actually
72get called.
74# DEFAULT
76NULL - use the internal progress meter. That is rarely wanted by users.
78# %PROTOCOLS%
80# EXAMPLE
82~~~c
83struct progress {
84 char *private_data;
85 size_t size;
86};
88static int xferinfo_callback(void *clientp,
89 curl_off_t dltotal,
90 curl_off_t dlnow,
91 curl_off_t ultotal,
92 curl_off_t ulnow)
94 struct progress *memory = clientp;
95 printf("my ptr: %p\n", (void *)memory->private_data);
97 /* use the values */
99 return 0; /* all is good */
102int main(void)
104 CURL *curl = curl_easy_init();
105 if(curl) {
106 struct progress data;
108 /* pass struct to callback */
109 curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &data);
111 /* enable progress callback getting called */
112 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
114 curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo_callback);
115 }
117~~~
119# %AVAILABILITY%
121# RETURN VALUE
123curl_easy_setopt(3) returns a CURLcode indicating success or error.
125CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
126libcurl-errors(3).
Diagnostics4 git calls · 133 ms
CallStatusSizeTime0133 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=UPDATING
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=129
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2001.6 KiB129 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1593
git.response.cache=MISS
git.response.duration_ms=129
git.fetch.wants=9c074b60f66c582521488b9971a91d804e92eb8d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1593
git.pkt.payload.max=1572
git.sideband.band1.bytes=1571
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e33c22fe47dafe
Request
74e21ff0…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format