Annotation of embedaddon/curl/docs/libcurl/opts/CURLMOPT_TIMERFUNCTION.3, revision 1.1
1.1 ! misho 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 "May 03, 2019" "libcurl 7.70.0" "curl_multi_setopt options"
! 24:
! 25: .SH NAME
! 26: CURLMOPT_TIMERFUNCTION \- set callback to receive timeout values
! 27: .SH SYNOPSIS
! 28: .nf
! 29: #include <curl/curl.h>
! 30:
! 31: int timer_callback(CURLM *multi, /* multi handle */
! 32: long timeout_ms, /* timeout in number of ms */
! 33: void *userp); /* private callback pointer */
! 34:
! 35: CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERFUNCTION, timer_callback);
! 36: .SH DESCRIPTION
! 37: Pass a pointer to your callback function, which should match the prototype
! 38: shown above.
! 39:
! 40: Certain features, such as timeouts and retries, require you to call libcurl
! 41: even when there is no activity on the file descriptors.
! 42:
! 43: Your callback function \fBtimer_callback\fP should install a non-repeating
! 44: timer with an interval of \fBtimeout_ms\fP. When time that timer fires, call
! 45: either \fIcurl_multi_socket_action(3)\fP or \fIcurl_multi_perform(3)\fP,
! 46: depending on which interface you use.
! 47:
! 48: A \fBtimeout_ms\fP value of -1 passed to this callback means you should delete
! 49: the timer. All other values are valid expire times in number of milliseconds.
! 50:
! 51: The \fBtimer_callback\fP will only be called when the timeout expire time is
! 52: changed.
! 53:
! 54: The \fBuserp\fP pointer is set with \fICURLMOPT_TIMERDATA(3)\fP.
! 55:
! 56: The timer callback should return 0 on success, and -1 on error. This callback
! 57: can be used instead of, or in addition to, \fIcurl_multi_timeout(3)\fP.
! 58:
! 59: \fBWARNING:\fP even if it feels tempting, avoid calling libcurl directly from
! 60: within the callback itself when the \fBtimeout_ms\fP value is zero, since it
! 61: risks triggering an unpleasant recursive behavior that immediately calls
! 62: another call to the callback with a zero timeout...
! 63: .SH DEFAULT
! 64: NULL
! 65: .SH PROTOCOLS
! 66: All
! 67: .SH EXAMPLE
! 68: .nf
! 69: static gboolean timeout_cb(gpointer user_data)
! 70: {
! 71: int running;
! 72: if(user_data) {
! 73: g_free(user_data);
! 74: curl_multi_setopt(curl_handle, CURLMOPT_TIMERDATA, NULL);
! 75: }
! 76: curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running);
! 77: return G_SOURCE_REMOVE;
! 78: }
! 79:
! 80: static int timerfunc(CURLM *multi, long timeout_ms, void *userp)
! 81: {
! 82: guint *id = userp;
! 83:
! 84: if(id)
! 85: g_source_remove(*id);
! 86:
! 87: /* -1 means we should just delete our timer. */
! 88: if(timeout_ms == -1) {
! 89: g_free(id);
! 90: id = NULL;
! 91: }
! 92: else {
! 93: if(!id)
! 94: id = g_new(guint, 1);
! 95: *id = g_timeout_add(timeout_ms, timeout_cb, id);
! 96: }
! 97: curl_multi_setopt(multi, CURLMOPT_TIMERDATA, id);
! 98: return 0;
! 99: }
! 100:
! 101: curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
! 102: .fi
! 103: .SH AVAILABILITY
! 104: Added in 7.16.0
! 105: .SH RETURN VALUE
! 106: Returns CURLM_OK if the option is supported, and CURLM_UNKNOWN_OPTION if not.
! 107: .SH "SEE ALSO"
! 108: .BR CURLMOPT_TIMERDATA "(3), " CURLMOPT_SOCKETFUNCTION "(3), "
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>