title: Libcurl - how can you explain this behavior curl_multi_poll
body: <p>This is my third question about curl_multi_poll, but now I seem to have done everything according to the rules:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;curl.h&gt;     
  
  int main()
  {
      curl_global_init(CURL_GLOBAL_ALL);
      CURLM* CURLM_ = curl_multi_init();
      CURL* CURL_ = curl_easy_init();
  
      curl_easy_setopt(CURL_, CURLOPT_URL, &quot;https://stackoverflow.com&quot;);
  
      int num_desc_events;
      int running_now;
  
      curl_multi_add_handle(CURLM_, CURL_);
      curl_multi_perform(CURLM_, &amp;running_now);
  
      while (1)
      {
          std::cout &lt;&lt; &quot;curl_multi_poll_start&quot; &lt;&lt; std::endl;
  
          curl_multi_poll(CURLM_, NULL, 0, 1000000, &amp;num_desc_events);
  
          std::cout &lt;&lt; &quot;curl_multi_poll_awakened&quot; &lt;&lt; std::endl;
          std::cout &lt;&lt; &quot;num_desc_events:&quot; &lt;&lt; num_desc_events &lt;&lt; std::endl;
  
          curl_multi_perform(CURLM_, &amp;running_now);
  
          std::cout &lt;&lt; &quot;curl_multi_perform_start&quot; &lt;&lt; std::endl;
          std::cout &lt;&lt; &quot;running_now:&quot; &lt;&lt; running_now &lt;&lt; std::endl;
          
      }
  
      curl_easy_cleanup(CURL_);
      curl_multi_cleanup(CURLM_);
      curl_global_cleanup();
  }
  </code></pre>
  <p>The console output will be as follows:</p>
  <pre><code>curl_multi_poll_start                   //Begin loop
  curl_multi_poll_awakened
  num_desc_events:1                       //curl_multi_poll awakened - and the number of sockets on which the event occurred is indicated 
  curl_multi_perform_start                //If there are sockets on which events have occurred, I run curl_multi_perform 
  running_now:1                           //number of sockets still in operation 
  curl_multi_poll_start
  curl_multi_poll_awakened
  num_desc_events:1
  curl_multi_perform_start
  running_now:1
  curl_multi_poll_start
  curl_multi_poll_awakened
  num_desc_events:0                      //Attention!!! Why does curl_multi_poll wake up if the number of sockets on which events have occurred is 0? 
  curl_multi_perform_start
  running_now:1
  curl_multi_poll_start
  curl_multi_poll_awakened
  num_desc_events:1
  curl_multi_perform_start
  running_now:1
  curl_multi_poll_start
  curl_multi_poll_awakened
  num_desc_events:0                         //The same 
  curl_multi_perform_start
  running_now:1
  curl_multi_poll_start
  curl_multi_poll_awakened
  num_desc_events:1
  curl_multi_perform_start
  running_now:1
  curl_multi_poll_start
  curl_multi_poll_awakened
  num_desc_events:1
  curl_multi_perform_start
  running_now:0                            //the number of sockets in operation is 0. Request completed. 
  curl_multi_poll_start                    //curl_multi_poll pending
  </code></pre>
  <p>From curl_multi_poll description: <a href="https://curl.se/libcurl/c/curl_multi_poll.html" rel="nofollow noreferrer">https://curl.se/libcurl/c/curl_multi_poll.html</a></p>
  <blockquote>
  <p>On completion, if numfds is non-NULL, it will be populated with the
  total number of file descriptors on which interesting events occurred.</p>
  </blockquote>
  <p>Actually the question is: why did curl_multi_poll wake up twice if there were no events on the socket?</p>