CURLMOPT_TIMERDATA.3 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 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.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. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLMOPT_TIMERDATA 3 "17 Jun 2014" libcurl libcurl
  26. .SH NAME
  27. CURLMOPT_TIMERDATA \- custom pointer to pass to timer callback
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERDATA, void *pointer);
  32. .SH DESCRIPTION
  33. A data \fBpointer\fP to pass to the timer callback set with the
  34. \fICURLMOPT_TIMERFUNCTION(3)\fP option.
  35. This pointer will not be touched by libcurl but will only be passed in to the
  36. timer callbacks's \fBclientp\fP argument.
  37. .SH DEFAULT
  38. NULL
  39. .SH PROTOCOLS
  40. All
  41. .SH EXAMPLE
  42. .nf
  43. static gboolean timeout_cb(gpointer user_data)
  44. {
  45. int running;
  46. if(user_data) {
  47. g_free(user_data);
  48. curl_multi_setopt(curl_handle, CURLMOPT_TIMERDATA, NULL);
  49. }
  50. curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running);
  51. return G_SOURCE_REMOVE;
  52. }
  53. static int timerfunc(CURLM *multi, long timeout_ms, void *clientp)
  54. {
  55. guint *id = clientp;
  56. if(id)
  57. g_source_remove(*id);
  58. /* -1 means we should just delete our timer. */
  59. if(timeout_ms == -1) {
  60. g_free(id);
  61. id = NULL;
  62. }
  63. else {
  64. if(!id)
  65. id = g_new(guint, 1);
  66. *id = g_timeout_add(timeout_ms, timeout_cb, id);
  67. }
  68. current_timer = id;
  69. return 0;
  70. }
  71. curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
  72. .fi
  73. .SH AVAILABILITY
  74. Added in 7.16.0
  75. .SH RETURN VALUE
  76. Returns CURLM_OK if the option is supported, and CURLM_UNKNOWN_OPTION if not.
  77. .SH "SEE ALSO"
  78. .BR CURLMOPT_TIMERFUNCTION "(3), " CURLMOPT_SOCKETFUNCTION "(3), "