• <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>

            colorful

            zc qq:1337220912

             

            libcurl 多線程使用注意事項

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

             

            最后通過查看資料和網(wǎng)上找的一些文章,發(fā)現(xiàn),原來是信號處理的問題:

             

             

            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等操作。如果不設(shè)置這個選項,libcurl將會發(fā)信號打斷這個wait從而導(dǎo)致程序退出。

             

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

            curl_setopt(curl, CURLOPT_NOSIGNAL, 1L);

             

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

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

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

            posted on 2013-12-02 17:16 多彩人生 閱讀(1549) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            色偷偷偷久久伊人大杳蕉| 91久久精品国产成人久久| 久久只这里是精品66| 亚洲精品无码久久久久AV麻豆| 亚洲午夜无码久久久久| A狠狠久久蜜臀婷色中文网| 久久久综合香蕉尹人综合网| 亚洲欧美日韩中文久久| 性高湖久久久久久久久AAAAA| 欧美亚洲色综久久精品国产| 91精品国产色综久久| 国产免费久久精品99re丫y| 久久精品亚洲乱码伦伦中文| 国内精品久久久久伊人av| 国产精品综合久久第一页 | 少妇久久久久久被弄高潮| 国产高清国内精品福利99久久| 久久人人爽人人爽人人片AV麻烦| 久久久久亚洲AV综合波多野结衣| 亚洲精品乱码久久久久久自慰| 久久99精品久久久久久野外| 国产精品久久免费| 久久天天躁狠狠躁夜夜网站| 久久天天躁狠狠躁夜夜av浪潮| 久久91精品久久91综合| 亚洲国产成人久久精品影视| 亚洲国产精品久久久天堂| 青青青青久久精品国产h久久精品五福影院1421| 亚洲午夜久久久久久噜噜噜| 中文字幕精品久久| 久久99这里只有精品国产| 久久久精品波多野结衣| 亚洲国产二区三区久久| 久久九九亚洲精品| 久久久久亚洲精品天堂久久久久久| 欧洲人妻丰满av无码久久不卡| 狠狠色丁香久久婷婷综合| 精品久久人人爽天天玩人人妻| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 99精品久久精品一区二区| 久久精品国产亚洲av麻豆蜜芽 |