• <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 多線程使用注意事項(xiàng)

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

             

            最后通過(guò)查看資料和網(wǎng)上找的一些文章,發(fā)現(xiàn),原來(lái)是信號(hào)處理的問(wè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. 

             

            就是當(dāng)多個(gè)線程都使用超時(shí)處理的時(shí)候,同時(shí)主線程中有sleep或是wait等操作。如果不設(shè)置這個(gè)選項(xiàng),libcurl將會(huì)發(fā)信號(hào)打斷這個(gè)wait從而導(dǎo)致程序退出。

             

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

            curl_setopt(curl, CURLOPT_NOSIGNAL, 1L);

             

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

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

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

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


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


            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久久久亚洲AV片无码下载蜜桃| 久久精品国产91久久麻豆自制| 一本色综合久久| 一本一本久久a久久综合精品蜜桃| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久国产精品久久| 无码8090精品久久一区| 亚洲&#228;v永久无码精品天堂久久| 国产国产成人久久精品| 久久精品中文字幕一区| 久久久91精品国产一区二区三区 | 国内精品久久久久伊人av| 99久久综合国产精品二区| 欧美粉嫩小泬久久久久久久| 精品综合久久久久久97超人 | 国产精品九九久久精品女同亚洲欧美日韩综合区 | 无码精品久久久久久人妻中字 | 久久婷婷色香五月综合激情| 国内精品久久久久久久涩爱| 色综合久久中文字幕无码| 久久久久综合国产欧美一区二区| 男女久久久国产一区二区三区| 久久无码专区国产精品发布| 久久国产影院| 久久国产精品免费一区| 91久久精品视频| 91精品观看91久久久久久 | 久久精品国产亚洲AV蜜臀色欲 | 日本人妻丰满熟妇久久久久久| 久久精品国产99国产精品| 久久99国产精品99久久| 99麻豆久久久国产精品免费| 久久久久无码精品国产| 久久精品欧美日韩精品| 久久精品国产亚洲av麻豆小说| 少妇精品久久久一区二区三区| 久久天堂AV综合合色蜜桃网| 国产午夜免费高清久久影院| 久久久噜噜噜久久熟女AA片| 国产精品久久亚洲不卡动漫| 久久精品视频网|