日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁西西教程操作系統(tǒng) → libevent調用evbuffer_add_file卡死問題解決

      libevent調用evbuffer_add_file卡死問題解決

      相關軟件相關文章發(fā)表評論 來源:stsword時間:2012/1/31 11:07:13字體大。A-A+

      作者:stsword點擊:65次評論:0次標簽: libevent

      • 類型:角色扮演大。18.1M語言:中文 評分:.0
      • 標簽:
      立即下載

      問題描述:

      今天想做一個簡單的HTTP服務器,發(fā)現(xiàn)libevent使用很方便,就用他的example里的httpserver代碼試了下,發(fā)現(xiàn)一個問題,就是在打開部分文件時候,服務器會卡住。沒有任何返回,瀏覽器一直處于等待狀態(tài)。
      后來調試后發(fā)現(xiàn),卡死在evbuffer_add_file函數(shù)。

      源代碼如下:

      01 /* Otherwise it's a file; add it to the buffer to get

      02 * sent via sendfile */

      03 const char *type = guess_content_type(decoded_path);

      04 if ((fd = open(whole_path, O_RDONLY)) < 0) {

      05 perror("open");

      06 goto err;

      07 }

      08 if (fstat(fd, &st)<0) {

      09 /* Make sure the length still matches, now that we

      10 * opened the file :/ */

      11 perror("fstat");

      12 goto err;

      13 }

      14 evhttp_add_header(evhttp_request_get_output_headers(req),

      15 "Content-Type", type);

      16 evbuffer_add_file(evb, fd, 0, st.st_size);

      后經(jīng)過調試發(fā)現(xiàn),是由于代碼第四行中打開文件的方式有問題。缺少O_BINARY標志,導致對于某些包含不可顯示或者中文的文件會卡死。
      改成如下代碼即可:

      1 /* Otherwise it's a file; add it to the buffer to get

      2 * sent via sendfile */

      3 const char *type = guess_content_type(decoded_path);

      4 if ((fd = open(whole_path, O_RDONLY|O_BINARY)) < 0) {

      5 perror("open");

      6 goto err;

      7 }

        相關評論

        閱讀本文后您有什么感想? 已有人給出評價!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        發(fā)表評論 查看所有評論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)