Artifactspublic-v0

curl

master
ply4 git calls158 ms288 KiB2 cachedprotocol v2
111 lines3.0 KiBRaw

NAME

CURLMOPT_TIMERFUNCTION - callback to receive timeout values

SYNOPSIS

c
#include <curl/curl.h>

int timer_callback(CURLM *multi,    /* multi handle */
                   long timeout_ms, /* timeout in number of ms */
                   void *clientp);  /* private callback pointer */

CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERFUNCTION, timer_callback);

DESCRIPTION

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

Certain features, such as timeouts and retries, require you to call libcurl even when there is no activity on the file descriptors.

Your callback function timer_callback should install a single non-repeating timer with an expire time of timeout_ms milliseconds. When that timer fires, call either curl_multi_socket_action(3) or curl_multi_perform(3), depending on which interface you use.

If this callback is called when a timer is already running, this new expire time replaces the former timeout. The application should then effectively cancel the old timeout and set a new timeout using this new expire time.

A timeout_ms value of -1 passed to this callback means you should delete the timer. All other values are valid expire times in number of milliseconds - including zero milliseconds.

The timer_callback is called when the timeout expire time is changed.

The clientp pointer is set with CURLMOPT_TIMERDATA(3).

The timer callback should return 0 on success, and -1 on error. If this callback returns error, all transfers currently in progress in this multi handle are aborted and made to fail.

This callback can be used instead of, or in addition to, curl_multi_timeout(3).

WARNING: do not call libcurl directly from within the callback itself when the timeout_ms value is zero, since it risks triggering an unpleasant recursive behavior that immediately calls another call to the callback with a zero timeout...

DEFAULT

NULL

%PROTOCOLS%

EXAMPLE

c
struct priv {
  void *custom;
};

static int timerfunc(CURLM *multi, long timeout_ms, void *clientp)
{
  struct priv *mydata = clientp;
  printf("our ptr: %p\n", mydata->custom);

  if(timeout_ms >= 0) {
    /* this is the new single timeout to wait for, including zero */
  }
  else {
    /* delete the timeout, nothing to wait for now */
  }
  return 0;
}

int main(void)
{
  struct priv mydata;
  CURLM *multi = curl_multi_init();
  curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
  curl_multi_setopt(multi, CURLMOPT_TIMERDATA, &mydata);
}

%AVAILABILITY%

RETURN VALUE

curl_multi_setopt(3) returns a CURLMcode indicating success or error.

CURLM_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: CURLMOPT_TIMERFUNCTION
5Section: 3
6Source: libcurl
7See-also:
8 - CURLMOPT_SOCKETFUNCTION (3)
9 - CURLMOPT_TIMERDATA (3)
10Protocol:
11 - All
12Added-in: 7.16.0
13---
15# NAME
17CURLMOPT_TIMERFUNCTION - callback to receive timeout values
19# SYNOPSIS
21~~~c
22#include <curl/curl.h>
24int timer_callback(CURLM *multi, /* multi handle */
25 long timeout_ms, /* timeout in number of ms */
26 void *clientp); /* private callback pointer */
28CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERFUNCTION, timer_callback);
29~~~
31# DESCRIPTION
33Pass a pointer to your callback function, which should match the prototype
34shown above.
36Certain features, such as timeouts and retries, require you to call libcurl
37even when there is no activity on the file descriptors.
39Your callback function **timer_callback** should install a single
40non-repeating timer with an expire time of **timeout_ms** milliseconds. When
41that timer fires, call either curl_multi_socket_action(3) or
42curl_multi_perform(3), depending on which interface you use.
44If this callback is called when a timer is already running, this new expire
45time *replaces* the former timeout. The application should then effectively
46cancel the old timeout and set a new timeout using this new expire time.
48A **timeout_ms** value of -1 passed to this callback means you should delete
49the timer. All other values are valid expire times in number of milliseconds -
50including zero milliseconds.
52The **timer_callback** is called when the timeout expire time is changed.
54The **clientp** pointer is set with CURLMOPT_TIMERDATA(3).
56The timer callback should return 0 on success, and -1 on error. If this
57callback returns error, **all** transfers currently in progress in this multi
58handle are aborted and made to fail.
60This callback can be used instead of, or in addition to,
61curl_multi_timeout(3).
63**WARNING:** do not call libcurl directly from within the callback itself when
64the **timeout_ms** value is zero, since it risks triggering an unpleasant
65recursive behavior that immediately calls another call to the callback with a
66zero timeout...
68# DEFAULT
70NULL
72# %PROTOCOLS%
74# EXAMPLE
76~~~c
77struct priv {
78 void *custom;
79};
81static int timerfunc(CURLM *multi, long timeout_ms, void *clientp)
83 struct priv *mydata = clientp;
84 printf("our ptr: %p\n", mydata->custom);
86 if(timeout_ms >= 0) {
87 /* this is the new single timeout to wait for, including zero */
88 }
89 else {
90 /* delete the timeout, nothing to wait for now */
91 }
92 return 0;
95int main(void)
97 struct priv mydata;
98 CURLM *multi = curl_multi_init();
99 curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
100 curl_multi_setopt(multi, CURLMOPT_TIMERDATA, &mydata);
102~~~
104# %AVAILABILITY%
106# RETURN VALUE
108curl_multi_setopt(3) returns a CURLMcode indicating success or error.
110CURLM_OK (0) means everything was OK, non-zero means an error occurred, see
111libcurl-errors(3).
Diagnostics4 git calls · 158 ms
CallStatusSizeTime0158 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 B · hit2 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=HIT
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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.5 KiB153 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=153
git.response.bytes=1511
git.response.cache=MISS
git.response.duration_ms=153
git.fetch.wants=ac55fb351bf9efe74b304d2f3d82be73fd687a81
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=1511
git.pkt.payload.max=1490
git.sideband.band1.bytes=1489
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
a5e34ae8aeee8a31
Request
9ff31e02…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format