comparison mupdf-source/thirdparty/curl/docs/libcurl/opts/CURLMOPT_TIMERFUNCTION.3 @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 .\" **************************************************************************
2 .\" * _ _ ____ _
3 .\" * Project ___| | | | _ \| |
4 .\" * / __| | | | |_) | |
5 .\" * | (__| |_| | _ <| |___
6 .\" * \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2019, 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.haxx.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 CURLMOPT_TIMERFUNCTION 3 "17 Jun 2014" "libcurl 7.37.0" "curl_multi_setopt options"
24 .SH NAME
25 CURLMOPT_TIMERFUNCTION \- set callback to receive timeout values
26 .SH SYNOPSIS
27 .nf
28 #include <curl/curl.h>
29
30 int timer_callback(CURLM *multi, /* multi handle */
31 long timeout_ms, /* timeout in number of ms */
32 void *userp); /* private callback pointer */
33
34 CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERFUNCTION, timer_callback);
35 .SH DESCRIPTION
36 Pass a pointer to your callback function, which should match the prototype
37 shown above.
38
39 Certain features, such as timeouts and retries, require you to call libcurl
40 even when there is no activity on the file descriptors.
41
42 Your callback function \fBtimer_callback\fP should install a non-repeating
43 timer with an interval of \fBtimeout_ms\fP. When time that timer fires, call
44 either \fIcurl_multi_socket_action(3)\fP or \fIcurl_multi_perform(3)\fP,
45 depending on which interface you use.
46
47 A \fBtimeout_ms\fP value of -1 passed to this callback means you should delete
48 the timer. All other values are valid expire times in number of milliseconds.
49
50 The \fBtimer_callback\fP will only be called when the timeout expire time is
51 changed.
52
53 The \fBuserp\fP pointer is set with \fICURLMOPT_TIMERDATA(3)\fP.
54
55 The timer callback should return 0 on success, and -1 on error. This callback
56 can be used instead of, or in addition to, \fIcurl_multi_timeout(3)\fP.
57
58 \fBWARNING:\fP even if it feels tempting, avoid calling libcurl directly from
59 within the callback itself when the \fBtimeout_ms\fP value is zero, since it
60 risks triggering an unpleasant recursive behavior that immediately calls
61 another call to the callback with a zero timeout...
62 .SH DEFAULT
63 NULL
64 .SH PROTOCOLS
65 All
66 .SH EXAMPLE
67 .nf
68 static gboolean timeout_cb(gpointer user_data)
69 {
70 int running;
71 if(user_data) {
72 g_free(user_data);
73 curl_multi_setopt(curl_handle, CURLMOPT_TIMERDATA, NULL);
74 }
75 curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running);
76 return G_SOURCE_REMOVE;
77 }
78
79 static int timerfunc(CURLM *multi, long timeout_ms, void *userp)
80 {
81 guint *id = userp;
82
83 if(id)
84 g_source_remove(*id);
85
86 /* -1 means we should just delete our timer. */
87 if(timeout_ms == -1) {
88 g_free(id);
89 id = NULL;
90 }
91 else {
92 if(!id)
93 id = g_new(guint, 1);
94 *id = g_timeout_add(timeout_ms, timeout_cb, id);
95 }
96 curl_multi_setopt(multi, CURLMOPT_TIMERDATA, id);
97 return 0;
98 }
99
100 curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
101 .fi
102 .SH AVAILABILITY
103 Added in 7.16.0
104 .SH RETURN VALUE
105 Returns CURLM_OK if the option is supported, and CURLM_UNKNOWN_OPTION if not.
106 .SH "SEE ALSO"
107 .BR CURLMOPT_TIMERDATA "(3), " CURLMOPT_SOCKETFUNCTION "(3), "