• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            牽著老婆滿街逛

            嚴以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            關于使用libcurl的注意事項

            libcurl與CLOSE_WAIT
            轉載自:http://blog.sunshow.net/2010/03/libcurl-and-close-wait/

            調用libcurl下載,然后使用netstat查看發現有大量的TCP連接保持在CLOSE_WAIT狀態
            查看libcurl的文檔說明,有這樣一個選項:

            CURLOPT_FORBID_REUSE

            Pass a long. Set to 1 to make the next transfer explicitly close the connection when done. Normally, libcurl keeps all connections alive when done with one transfer in case a succeeding one follows that can re-use them. This option should be used with caution and only if you understand what it does. Set to 0 to have libcurl keep the connection open for possible later re-use (default behavior).

            也就是說,默認情況下libcurl完成一個任務以后,出于重用連接的考慮不會馬上關閉
            如果沒有新的TCP請求來重用這個連接,那么只能等到CLOSE_WAIT超時,這個時間默認在7200秒甚至更高,太多的CLOSE_WAIT連接會導致性能問題

            解決方法:

            curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);

             最好再修改一下TCP參數調低CLOSE_WAIT和TIME_WAIT的超時時間




            libcurl 使用筆記
            轉載自:http://gcoder.blogbus.com/logs/54871550.html

            libcurl 是一個很不錯的庫,支持http,ftp等很多的協議。使用庫最大的心得就是,不仔細看文檔,僅僅看著例子就寫程序,是一件危險的事情。我的程序崩潰了,我懷疑是自己代碼寫的問題,后來發現是庫沒用對。不仔細看文檔(有時候文檔本身也比較差勁,這時除了看仔細外,還要多動腦子,考慮它是怎么實現的),后果很嚴重。不加思索的使用別人的庫或者代碼,有時候很愜意,但是出問題時,卻是寢食難安的。

            1. CURLcode curl_global_init(long flags); 在多線程應用中,需要在主線程中調用這個函數。這個函數設置libcurl所需的環境。通常情況,如果不顯式的調用它,第一次調用curl_easy_init()時,curl_easy_init 會調用 curl_global_init,在單線程環境下,這不是問題。但是多線程下就不行了,因為curl_global_init不是線程安全的。在多個線程中調用curl_easy_int,然后如果兩個線程同時發現curl_global_init還沒有被調用,同時調用curl_global_init,悲劇就發生了。這種情況發生的概率很小,但可能性是存在的。

            2. libcurl 有個很好的特性,它甚至可以控制域名解析的超時。但是在默認情況下,它是使用alarm + siglongjmp 實現的。用alarm在多線程下做超時,本身就幾乎不可能。如果只是使用alarm,并不會導致程序崩潰,但是,再加上siglongjmp,就要命了(程序崩潰的很可怕,core中幾乎看不出有用信息),因為其需要一個sigjmp_buf型的全局變量,多線程修改它。(通常情況下,可以每個線程一個 sigjmp_buf 型的變量,這種情況下,多線程中使用 siglongjmp 是沒有問題的,但是libcurl只有一個全局變量,所有的線程都會用)。

              具體是類似 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L) 的超時設置,導致alarm的使用(估計發生在域名解析階段),如前所述,這在多線程中是不行的。解決方式是禁用掉alarm這種超時, curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L)。

              這樣,多線程中使用超時就安全了。但是域名解析就沒了超時機制,碰到很慢的域名解析,也很麻煩。文檔的建議是 Consider building libcurl with c-ares support to enable asynchronous DNS lookups, which enables nice timeouts for name resolves without signals.  c-ares 是異步的 DNS 解決方案。




             libcurl 多線程使用注意事項
            轉載自:http://blog.csdn.net/jaylong35/article/details/6439549

            1、問題來源,多線程使用Libcurl導致程序跑一段時間后自己退出,沒有明顯的異常。找不到合適的BUG。

             最后通過查看資料和網上找的一些文章,發現,原來是信號處理的問題:

            CURLOPT_NOSIGNAL

            Pass a long. If it is 1, libcurl will not use any functions that install signal handlers or any functions that cause signals to be sent to the process. This option is mainly here to allow multi-threaded unix applications to still set/use all timeout options etc, without risking getting signals. (Added in 7.10)

            If this option is set and libcurl has been built with the standard name resolver, timeouts will not occur while the name resolve takes place. Consider building libcurl with c-ares support to enable asynchronous DNS lookups, which enables nice timeouts for name resolves without signals.

            Setting CURLOPT_NOSIGNAL to 1 makes libcurl NOT ask the system to ignore SIGPIPE signals, which otherwise are sent by the system when trying to send data to a socket which is closed in the other end. libcurl makes an effort to never cause such SIGPIPEs to trigger, but some operating systems have no way to avoid them and even on those that have there are some corner cases when they may still happen, contrary to our desire. 

            就是當多個線程都使用超時處理的時候,同時主線程中有sleep或是wait等操作。如果不設置這個選項,libcurl將會發信號打斷這個wait從而導致程序退出。

            所以,在使用的時候把這個選項設置成1就可以了.

            curl_setopt(curl, CURLOPT_NOSIGNAL, 1L);


            2、關于libcurl庫的初始化和關閉:curl_global_init()和curl_global_cleanup()

            這兩個函數并不是線程安全的。所以只能在主線程中進行一次的初始化和清除。

            雖然這個不是一定就會有問題,但是如果不這樣處理還是有概率發生的。

            posted on 2012-02-20 11:39 楊粼波 閱讀(3590) 評論(0)  編輯 收藏 引用 所屬分類: 文章收藏網絡編程C++

            久久香蕉一级毛片| 久久国产精品99精品国产| 久久国产精品-国产精品| 国产V综合V亚洲欧美久久| 91精品国产色综久久| 婷婷久久五月天| 久久天堂AV综合合色蜜桃网 | 四虎亚洲国产成人久久精品| 亚洲午夜无码久久久久小说 | 成人资源影音先锋久久资源网| 久久午夜电影网| 国内精品九九久久精品| 久久99精品久久久久久| 久久免费视频1| 国产成人精品综合久久久| 久久妇女高潮几次MBA| 一本色道久久88加勒比—综合| 久久综合久久综合亚洲| 香蕉久久夜色精品国产小说| 亚洲伊人久久成综合人影院 | 亚洲欧美成人综合久久久| 国产亚州精品女人久久久久久| 香蕉久久av一区二区三区| 青青热久久国产久精品 | 丁香五月综合久久激情| 久久国产乱子伦精品免费午夜| 97久久国产露脸精品国产| 99久久国产综合精品五月天喷水| 亚洲国产精品无码久久一区二区| 久久久久亚洲AV无码专区桃色| 久久91精品国产91久久麻豆| 人妻精品久久久久中文字幕一冢本| 久久综合久久综合亚洲| 久久久久免费视频| 久久精品?ⅴ无码中文字幕| 99精品伊人久久久大香线蕉| 7777久久亚洲中文字幕| av无码久久久久久不卡网站| 久久婷婷激情综合色综合俺也去| 亚洲va久久久噜噜噜久久天堂| 97久久超碰成人精品网站|