xref: /curl/docs/libcurl/curl_multi_wakeup.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_multi_wakeup
5Section: 3
6Source: libcurl
7See-also:
8  - curl_multi_poll (3)
9  - curl_multi_wait (3)
10Protocol:
11  - All
12Added-in: 7.68.0
13---
14
15# NAME
16
17curl_multi_wakeup - wake up a sleeping curl_multi_poll call
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLMcode curl_multi_wakeup(CURLM *multi_handle);
25~~~
26
27# DESCRIPTION
28
29This function can be called from any thread and it wakes up a sleeping
30curl_multi_poll(3) call that is currently (or is about to be) waiting
31for activity or a timeout.
32
33If the function is called when there is no curl_multi_poll(3) call, it
34causes the next call to return immediately.
35
36Calling this function only guarantees to wake up the current (or the next if
37there is no current) curl_multi_poll(3) call, which means it is possible
38that multiple calls to this function wake up the same waiting operation.
39
40This function has no effect on curl_multi_wait(3) calls.
41
42# %PROTOCOLS%
43
44# EXAMPLE
45
46~~~c
47extern int time_to_die(void);
48extern int set_something_to_signal_thread_1_to_exit(void);
49extern int decide_to_stop_thread1();
50
51int main(void)
52{
53  CURL *easy;
54  CURLM *multi;
55  int still_running;
56
57  /* add the individual easy handle */
58  curl_multi_add_handle(multi, easy);
59
60  /* this is thread 1 */
61  do {
62    CURLMcode mc;
63    int numfds;
64
65    mc = curl_multi_perform(multi, &still_running);
66
67    if(mc == CURLM_OK) {
68      /* wait for activity, timeout or wakeup */
69      mc = curl_multi_poll(multi, NULL, 0, 10000, &numfds);
70    }
71
72    if(time_to_die())
73      return 1;
74
75  } while(still_running);
76
77  curl_multi_remove_handle(multi, easy);
78
79  /* this is thread 2 */
80
81  if(decide_to_stop_thread1()) {
82
83    set_something_to_signal_thread_1_to_exit();
84
85    curl_multi_wakeup(multi);
86  }
87}
88~~~
89
90# %AVAILABILITY%
91
92# RETURN VALUE
93
94CURLMcode type, general libcurl multi interface error code.
95