久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='r4OPG'></tfoot>
    • <bdo id='r4OPG'></bdo><ul id='r4OPG'></ul>

  • <i id='r4OPG'><tr id='r4OPG'><dt id='r4OPG'><q id='r4OPG'><span id='r4OPG'><b id='r4OPG'><form id='r4OPG'><ins id='r4OPG'></ins><ul id='r4OPG'></ul><sub id='r4OPG'></sub></form><legend id='r4OPG'></legend><bdo id='r4OPG'><pre id='r4OPG'><center id='r4OPG'></center></pre></bdo></b><th id='r4OPG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='r4OPG'><tfoot id='r4OPG'></tfoot><dl id='r4OPG'><fieldset id='r4OPG'></fieldset></dl></div>
  • <small id='r4OPG'></small><noframes id='r4OPG'>

    <legend id='r4OPG'><style id='r4OPG'><dir id='r4OPG'><q id='r4OPG'></q></dir></style></legend>

        如何在 C++ 中異步執行 curl_multi_perform()?

        How to do curl_multi_perform() asynchronously in C++?(如何在 C++ 中異步執行 curl_multi_perform()?)
          <bdo id='IaQ2w'></bdo><ul id='IaQ2w'></ul>
            1. <legend id='IaQ2w'><style id='IaQ2w'><dir id='IaQ2w'><q id='IaQ2w'></q></dir></style></legend>

                  <tfoot id='IaQ2w'></tfoot>
                    <tbody id='IaQ2w'></tbody>

                  <small id='IaQ2w'></small><noframes id='IaQ2w'>

                  <i id='IaQ2w'><tr id='IaQ2w'><dt id='IaQ2w'><q id='IaQ2w'><span id='IaQ2w'><b id='IaQ2w'><form id='IaQ2w'><ins id='IaQ2w'></ins><ul id='IaQ2w'></ul><sub id='IaQ2w'></sub></form><legend id='IaQ2w'></legend><bdo id='IaQ2w'><pre id='IaQ2w'><center id='IaQ2w'></center></pre></bdo></b><th id='IaQ2w'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IaQ2w'><tfoot id='IaQ2w'></tfoot><dl id='IaQ2w'><fieldset id='IaQ2w'></fieldset></dl></div>
                  本文介紹了如何在 C++ 中異步執行 curl_multi_perform()?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我開始使用 curl 同步處理 http 請求.我的問題是如何異步執行此操作?

                  我做了一些搜索,從這個curl_multi_*接口的文檔-synchronous-or-asynchronous">問題 和這個 示例 但它根本沒有解決任何問題.

                  我的簡化代碼:

                  CURLM *curlm;int handle_count = 0;curlm = curl_multi_init();卷曲 *卷曲 = NULL;curl = curl_easy_init();如果(卷曲){curl_easy_setopt(curl, CURLOPT_URL, "https://stackoverflow.com/");curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);curl_multi_add_handle(卷曲,卷曲);curl_multi_perform(卷曲,&handle_count);}curl_global_cleanup();

                  回調方法 writeCallback 沒有被調用,什么也沒有發生.

                  請多多指教.

                  根據@Remy 的以下回答,我得到了這個,但似乎并不是我真正需要的.因為使用循環仍然是一個阻塞循環.如果我做錯或誤解了什么,請告訴我.實際上,我對 C++ 還很陌生.

                  這是我的代碼:

                  int main(int argc, const char * argv[]){使用命名空間標準;卷曲 *卷曲;int handle_count;curlm = curl_multi_init();卷曲 *curl1 = NULL;curl1 = curl_easy_init();卷曲 *curl2 = NULL;curl2 = curl_easy_init();if(curl1 && curl2){curl_easy_setopt(curl1, CURLOPT_URL, "https://stackoverflow.com/");curl_easy_setopt(curl1, CURLOPT_WRITEFUNCTION, writeCallback);curl_multi_add_handle(卷曲,curl1);curl_easy_setopt(curl2, CURLOPT_URL, "http://google.com/");curl_easy_setopt(curl2, CURLOPT_WRITEFUNCTION, writeCallback);curl_multi_add_handle(卷曲,curl2);CURLMcode 代碼;同時(1){代碼 = curl_multi_perform(curlm, &handle_count);如果(句柄計數== 0){休息;}}}curl_global_cleanup();cout<<"你好,世界!
                  ";返回0;}

                  我現在可以同時執行 2 個 http 請求.回調被調用但仍需要在執行以下行之前完成.我需要考慮線程嗎?

                  解決方案

                  再次仔細閱讀文檔,尤其是以下部分:

                  http://curl.haxx.se/libcurl/c/libcurl-multi.html

                  <塊引用>

                  你的應用程序可以從 libcurl 獲取知識,當它想要被調用來傳輸數據時,這樣你就不必忙循環并調用它 curl_multi_perform(3) 像瘋了一樣.curl_multi_fdset(3) 提供了一個界面,您可以使用它從 libcurl 中提取 fd_sets 以在選擇中使用() 或 poll() 調用以了解何時可能需要注意多堆棧中的傳輸.這也使您的程序可以很容易地同時等待對您自己的私有文件描述符的輸入,或者可能時不時地超時(如果您愿意的話).

                  http://curl.haxx.se/libcurl/c/curl_multi_perform.html><塊引用>

                  當應用程序發現有數據可用于 multi_handle 或超時已過時,應用程序應調用此函數來讀取/寫入現在要讀取或寫入的任何內容等. curl_multi_perform() 在讀/寫完成后立即返回.該函數不需要實際有任何數據可供讀取或可以寫入數據,可以調用它以防萬一.它將在第二個參數的整數指針中寫入仍在傳輸數據的句柄數.

                  如果 running_handles 的數量與上一次調用相比發生了變化(或者小于您添加到多句柄的簡單句柄數量),則您知道存在一次或多次轉移少跑".然后,您可以調用 curl_multi_info_read(3) 以獲取有關每個已完成傳輸的信息,返回的信息包括CURLcode 等.如果添加的句柄很快失敗,它可能永遠不會算作 running_handle.

                  當該函數返回時 running_handles 設置為零 (0) 時,不再有任何傳輸正在進行.

                  換句話說,你需要運行一個循環來輪詢 libcurl 的狀態,每當有數據等待傳輸時調用 curl_multi_perform(),根據需要重復,直到沒有任何數據可以傳輸.

                  您鏈接到的博客文章提到了這種循環:

                  <塊引用>

                  代碼可以這樣使用

                  http http;
                  http:AddRequest("http://www.google.com");

                  //在一些稱為每一幀的更新循環中
                  http:Update();

                  您沒有在代碼中進行任何循環,這就是沒有調用回調的原因.當您調用 curl_multi_perform() 一次時,尚未收到新數據.

                  I have come to use curl synchronously doing a http request. My question is how can I do it asynchronously?

                  I did some searches which lead me to the documentation of curl_multi_* interface from this question and this example but it didn't solve anything at all.

                  My simplified code:

                  CURLM *curlm;
                  int handle_count = 0;
                  curlm = curl_multi_init();
                  
                  CURL *curl = NULL;
                  curl = curl_easy_init();
                  
                  if(curl)
                  {
                      curl_easy_setopt(curl, CURLOPT_URL, "https://stackoverflow.com/");
                      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
                      curl_multi_add_handle(curlm, curl);
                      curl_multi_perform(curlm, &handle_count);
                  }
                  
                  curl_global_cleanup();
                  

                  The callback method writeCallback doesn't get called and nothing happens.

                  Please advise me.

                  EDIT:

                  According to @Remy's below answer, I got this but seems that it's not quite what I really needed. Cause using a loop is still a blocking one. Please tell me if I'm doing wrong or misunderstanding something. I'm actually pretty new to C++.

                  Here's my code again:

                  int main(int argc, const char * argv[])
                  {
                      using namespace std;
                      CURLM *curlm;
                      int handle_count;
                      curlm = curl_multi_init();
                  
                      CURL *curl1 = NULL;
                      curl1 = curl_easy_init();
                  
                      CURL *curl2 = NULL;
                      curl2 = curl_easy_init();
                  
                      if(curl1 && curl2)
                      {
                          curl_easy_setopt(curl1, CURLOPT_URL, "https://stackoverflow.com/");
                          curl_easy_setopt(curl1, CURLOPT_WRITEFUNCTION, writeCallback);
                          curl_multi_add_handle(curlm, curl1);
                  
                          curl_easy_setopt(curl2, CURLOPT_URL, "http://google.com/");
                          curl_easy_setopt(curl2, CURLOPT_WRITEFUNCTION, writeCallback);
                          curl_multi_add_handle(curlm, curl2);
                  
                          CURLMcode code;
                          while(1)
                          {
                              code = curl_multi_perform(curlm, &handle_count);
                  
                              if(handle_count == 0)
                              {
                                  break;
                              }
                          }
                      }
                  
                      curl_global_cleanup();
                  
                      cout << "Hello, World!
                  ";
                      return 0;
                  }
                  

                  I can now do 2 http requests simultaneously. Callbacks are called but still need to finish before executing following lines. Will I have to think of thread?

                  解決方案

                  Read the documentation again more carefully, particularly these portions:

                  http://curl.haxx.se/libcurl/c/libcurl-multi.html

                  Your application can acquire knowledge from libcurl when it would like to get invoked to transfer data, so that you don't have to busy-loop and call that curl_multi_perform(3) like crazy. curl_multi_fdset(3) offers an interface using which you can extract fd_sets from libcurl to use in select() or poll() calls in order to get to know when the transfers in the multi stack might need attention. This also makes it very easy for your program to wait for input on your own private file descriptors at the same time or perhaps timeout every now and then, should you want that.

                  http://curl.haxx.se/libcurl/c/curl_multi_perform.html

                  When an application has found out there's data available for the multi_handle or a timeout has elapsed, the application should call this function to read/write whatever there is to read or write right now etc. curl_multi_perform() returns as soon as the reads/writes are done. This function does not require that there actually is any data available for reading or that data can be written, it can be called just in case. It will write the number of handles that still transfer data in the second argument's integer-pointer.

                  If the amount of running_handles is changed from the previous call (or is less than the amount of easy handles you've added to the multi handle), you know that there is one or more transfers less "running". You can then call curl_multi_info_read(3) to get information about each individual completed transfer, and that returned info includes CURLcode and more. If an added handle fails very quickly, it may never be counted as a running_handle.

                  When running_handles is set to zero (0) on the return of this function, there is no longer any transfers in progress.

                  In other words, you need to run a loop that polls libcurl for its status, calling curl_multi_perform() whenever there is data waiting to be transferred, repeating as needed until there is nothing left to transfer.

                  The blog article you linked to mentions this looping:

                  The code can be used like

                  Http http;
                  http:AddRequest("http://www.google.com");

                  // In some update loop called each frame
                  http:Update();

                  You are not doing any looping in your code, that is why your callback is not being called. New data has not been received yet when you call curl_multi_perform() one time.

                  這篇關于如何在 C++ 中異步執行 curl_multi_perform()?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                  When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)
                    <legend id='1WE0y'><style id='1WE0y'><dir id='1WE0y'><q id='1WE0y'></q></dir></style></legend>
                  • <tfoot id='1WE0y'></tfoot>

                    <small id='1WE0y'></small><noframes id='1WE0y'>

                  • <i id='1WE0y'><tr id='1WE0y'><dt id='1WE0y'><q id='1WE0y'><span id='1WE0y'><b id='1WE0y'><form id='1WE0y'><ins id='1WE0y'></ins><ul id='1WE0y'></ul><sub id='1WE0y'></sub></form><legend id='1WE0y'></legend><bdo id='1WE0y'><pre id='1WE0y'><center id='1WE0y'></center></pre></bdo></b><th id='1WE0y'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1WE0y'><tfoot id='1WE0y'></tfoot><dl id='1WE0y'><fieldset id='1WE0y'></fieldset></dl></div>

                      <bdo id='1WE0y'></bdo><ul id='1WE0y'></ul>

                          <tbody id='1WE0y'></tbody>
                          • 主站蜘蛛池模板: 国产欧美在线观看 | 日本久久精品视频 | 成人免费视频网站在线观看 | 亚洲精品一区在线观看 | 日本久久综合网 | 精品免费国产一区二区三区 | 日韩精品视频在线 | 91丨国产| 国产99在线 | 欧美 | 一区二区精品 | 人人干人人干人人 | 国产成人在线一区二区 | 久久手机在线视频 | 国产精品国产精品国产专区不蜜 | 国产探花在线精品一区二区 | 91精品国产一区二区三区 | 日本天堂一区二区 | 国产精品一区一区三区 | 久久久久久久久国产成人免费 | 国产 欧美 日韩 一区 | 草草视频在线观看 | 精品一区国产 | 成人毛片一区二区三区 | av色噜噜 | 日韩超碰| 欧美性tv| caoporn地址| 一级欧美日韩 | 亚洲av毛片成人精品 | www.亚洲国产精品 | 日韩久久久久 | 国产超碰人人爽人人做人人爱 | 亚洲欧美一区二区三区在线 | 手机在线不卡av | 毛片在线免费 | 久久精品欧美电影 | 国产区免费视频 | 欧美性久久 | 中文字幕日本一区二区 | 精品久久久久久18免费网站 | 国产我和子的乱视频网站 |