• <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久久久久久董美香| 国内精品久久久久久久涩爱 | 国产精自产拍久久久久久蜜| 国产午夜电影久久| 久久这里的只有是精品23| 久久久www免费人成精品| 国产精品一区二区久久| 久久综合五月丁香久久激情| 久久精品中文字幕无码绿巨人| 少妇人妻综合久久中文字幕| 色偷偷888欧美精品久久久| 久久夜色精品国产噜噜亚洲a| 国产精品久久久久久| 怡红院日本一道日本久久| 色综合久久天天综线观看| 狠狠色丁香久久综合五月| 久久精品国产亚洲AV蜜臀色欲| 久久伊人精品青青草原高清| 亚洲欧洲久久久精品| 久久精品成人免费观看97| 国产精品9999久久久久| 无码久久精品国产亚洲Av影片| 久久夜色撩人精品国产小说| 久久精品国产91久久综合麻豆自制| 少妇人妻综合久久中文字幕| 内射无码专区久久亚洲| 久久99精品久久久久久9蜜桃| 好属妞这里只有精品久久| 亚洲精品无码久久久久去q | 精品久久久久久中文字幕人妻最新 | 久久久久国色AV免费观看| 国产精品久久自在自线观看| | 精品综合久久久久久88小说 | 久久精品国产99国产精品| 久久中文娱乐网| 久久亚洲国产午夜精品理论片| 久久久久亚洲AV无码永不| 亚洲欧美日韩中文久久|