quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

curl_multi_wakeup.md (2055B)


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