How to use libcurl upload stream data by HTTP/2?












1















DESCRIPTION



I'm working on a project that use libcurl with http/2 to upload stream data.



The workflow is:



data producer --> buffer --> curl --> server.



read_cb setted by CURLOPT_READFUNCTION will fetch data from the buffer when the sock is ready to send.




  1. When the curl fetch data too fast, the buffer may be empty. The empty buffer can cause read_cb to return 0, then I can't use the curl handle to send data anymore.(CURLOPT_READFUNCTION)


  2. I use curl_easy_pause to prevent read_cb return 0. I just want to pause calling read_cb(Only set CURL_READFUNC_PAUSE), but it seems that the write_cb is paused too, so I can't recv data(can capture data recved by wireshark).



QUESTION



What's the solution for stream upload using libcurl?
or any step i get wrong?



Thanks for suggestion.



my example code:



size_t read_cb(void* ptr, size_t size, size_t nitems, void* userdata) {
Buffer* buf = (Buffer*)userdata;
if (buf->empty())
return CURL_READFUNC_PAUSE;
...
}
size_t Buffer::put(const char* data, size_t* len) {
...
curl_easy_pause(easy_, CURL_READFUNC_PAUSE);
...
}









share|improve this question























  • i find that when put into buffer, call curl_easy_pause(easy_, CURLPAUSE_SEND_CONT) works.

    – K. Hao
    Jan 1 at 9:02
















1















DESCRIPTION



I'm working on a project that use libcurl with http/2 to upload stream data.



The workflow is:



data producer --> buffer --> curl --> server.



read_cb setted by CURLOPT_READFUNCTION will fetch data from the buffer when the sock is ready to send.




  1. When the curl fetch data too fast, the buffer may be empty. The empty buffer can cause read_cb to return 0, then I can't use the curl handle to send data anymore.(CURLOPT_READFUNCTION)


  2. I use curl_easy_pause to prevent read_cb return 0. I just want to pause calling read_cb(Only set CURL_READFUNC_PAUSE), but it seems that the write_cb is paused too, so I can't recv data(can capture data recved by wireshark).



QUESTION



What's the solution for stream upload using libcurl?
or any step i get wrong?



Thanks for suggestion.



my example code:



size_t read_cb(void* ptr, size_t size, size_t nitems, void* userdata) {
Buffer* buf = (Buffer*)userdata;
if (buf->empty())
return CURL_READFUNC_PAUSE;
...
}
size_t Buffer::put(const char* data, size_t* len) {
...
curl_easy_pause(easy_, CURL_READFUNC_PAUSE);
...
}









share|improve this question























  • i find that when put into buffer, call curl_easy_pause(easy_, CURLPAUSE_SEND_CONT) works.

    – K. Hao
    Jan 1 at 9:02














1












1








1








DESCRIPTION



I'm working on a project that use libcurl with http/2 to upload stream data.



The workflow is:



data producer --> buffer --> curl --> server.



read_cb setted by CURLOPT_READFUNCTION will fetch data from the buffer when the sock is ready to send.




  1. When the curl fetch data too fast, the buffer may be empty. The empty buffer can cause read_cb to return 0, then I can't use the curl handle to send data anymore.(CURLOPT_READFUNCTION)


  2. I use curl_easy_pause to prevent read_cb return 0. I just want to pause calling read_cb(Only set CURL_READFUNC_PAUSE), but it seems that the write_cb is paused too, so I can't recv data(can capture data recved by wireshark).



QUESTION



What's the solution for stream upload using libcurl?
or any step i get wrong?



Thanks for suggestion.



my example code:



size_t read_cb(void* ptr, size_t size, size_t nitems, void* userdata) {
Buffer* buf = (Buffer*)userdata;
if (buf->empty())
return CURL_READFUNC_PAUSE;
...
}
size_t Buffer::put(const char* data, size_t* len) {
...
curl_easy_pause(easy_, CURL_READFUNC_PAUSE);
...
}









share|improve this question














DESCRIPTION



I'm working on a project that use libcurl with http/2 to upload stream data.



The workflow is:



data producer --> buffer --> curl --> server.



read_cb setted by CURLOPT_READFUNCTION will fetch data from the buffer when the sock is ready to send.




  1. When the curl fetch data too fast, the buffer may be empty. The empty buffer can cause read_cb to return 0, then I can't use the curl handle to send data anymore.(CURLOPT_READFUNCTION)


  2. I use curl_easy_pause to prevent read_cb return 0. I just want to pause calling read_cb(Only set CURL_READFUNC_PAUSE), but it seems that the write_cb is paused too, so I can't recv data(can capture data recved by wireshark).



QUESTION



What's the solution for stream upload using libcurl?
or any step i get wrong?



Thanks for suggestion.



my example code:



size_t read_cb(void* ptr, size_t size, size_t nitems, void* userdata) {
Buffer* buf = (Buffer*)userdata;
if (buf->empty())
return CURL_READFUNC_PAUSE;
...
}
size_t Buffer::put(const char* data, size_t* len) {
...
curl_easy_pause(easy_, CURL_READFUNC_PAUSE);
...
}






curl http2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 7:35









K. HaoK. Hao

61




61













  • i find that when put into buffer, call curl_easy_pause(easy_, CURLPAUSE_SEND_CONT) works.

    – K. Hao
    Jan 1 at 9:02



















  • i find that when put into buffer, call curl_easy_pause(easy_, CURLPAUSE_SEND_CONT) works.

    – K. Hao
    Jan 1 at 9:02

















i find that when put into buffer, call curl_easy_pause(easy_, CURLPAUSE_SEND_CONT) works.

– K. Hao
Jan 1 at 9:02





i find that when put into buffer, call curl_easy_pause(easy_, CURLPAUSE_SEND_CONT) works.

– K. Hao
Jan 1 at 9:02












1 Answer
1






active

oldest

votes


















0














Follow these three steps:





  1. I need to install nghttp2 from GitHUB with



    sudo apt-get install git g++ make binutils autoconf automake autotools-dev libtool pkg-config 
    zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev
    libjemalloc-dev cython python3-dev python-setuptools
    git clone https://github.com/tatsuhiro-t/nghttp2.git
    cd nghttp2
    autoreconf -i
    automake
    autoconf
    ./configure
    make
    sudo maeke install



  2. Upgrade you curl version with



    cd ~
    sudo apt-get build-dep curl

    wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2
    tar -xvjf curl-7.46.0.tar.bz2
    cd curl-7.46.0
    ./configure --with-nghttp2=/usr/local --with-ssl
    sudo make && make install

    echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
    ldconfig



  3. Execute the following command



    cur —version







share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993805%2fhow-to-use-libcurl-upload-stream-data-by-http-2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Follow these three steps:





    1. I need to install nghttp2 from GitHUB with



      sudo apt-get install git g++ make binutils autoconf automake autotools-dev libtool pkg-config 
      zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev
      libjemalloc-dev cython python3-dev python-setuptools
      git clone https://github.com/tatsuhiro-t/nghttp2.git
      cd nghttp2
      autoreconf -i
      automake
      autoconf
      ./configure
      make
      sudo maeke install



    2. Upgrade you curl version with



      cd ~
      sudo apt-get build-dep curl

      wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2
      tar -xvjf curl-7.46.0.tar.bz2
      cd curl-7.46.0
      ./configure --with-nghttp2=/usr/local --with-ssl
      sudo make && make install

      echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
      ldconfig



    3. Execute the following command



      cur —version







    share|improve this answer






























      0














      Follow these three steps:





      1. I need to install nghttp2 from GitHUB with



        sudo apt-get install git g++ make binutils autoconf automake autotools-dev libtool pkg-config 
        zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev
        libjemalloc-dev cython python3-dev python-setuptools
        git clone https://github.com/tatsuhiro-t/nghttp2.git
        cd nghttp2
        autoreconf -i
        automake
        autoconf
        ./configure
        make
        sudo maeke install



      2. Upgrade you curl version with



        cd ~
        sudo apt-get build-dep curl

        wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2
        tar -xvjf curl-7.46.0.tar.bz2
        cd curl-7.46.0
        ./configure --with-nghttp2=/usr/local --with-ssl
        sudo make && make install

        echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
        ldconfig



      3. Execute the following command



        cur —version







      share|improve this answer




























        0












        0








        0







        Follow these three steps:





        1. I need to install nghttp2 from GitHUB with



          sudo apt-get install git g++ make binutils autoconf automake autotools-dev libtool pkg-config 
          zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev
          libjemalloc-dev cython python3-dev python-setuptools
          git clone https://github.com/tatsuhiro-t/nghttp2.git
          cd nghttp2
          autoreconf -i
          automake
          autoconf
          ./configure
          make
          sudo maeke install



        2. Upgrade you curl version with



          cd ~
          sudo apt-get build-dep curl

          wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2
          tar -xvjf curl-7.46.0.tar.bz2
          cd curl-7.46.0
          ./configure --with-nghttp2=/usr/local --with-ssl
          sudo make && make install

          echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
          ldconfig



        3. Execute the following command



          cur —version







        share|improve this answer















        Follow these three steps:





        1. I need to install nghttp2 from GitHUB with



          sudo apt-get install git g++ make binutils autoconf automake autotools-dev libtool pkg-config 
          zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev
          libjemalloc-dev cython python3-dev python-setuptools
          git clone https://github.com/tatsuhiro-t/nghttp2.git
          cd nghttp2
          autoreconf -i
          automake
          autoconf
          ./configure
          make
          sudo maeke install



        2. Upgrade you curl version with



          cd ~
          sudo apt-get build-dep curl

          wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2
          tar -xvjf curl-7.46.0.tar.bz2
          cd curl-7.46.0
          ./configure --with-nghttp2=/usr/local --with-ssl
          sudo make && make install

          echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
          ldconfig



        3. Execute the following command



          cur —version








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 20:00









        zx485

        14.5k133047




        14.5k133047










        answered Jan 1 at 7:52









        len.rongfulen.rongfu

        1




        1
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993805%2fhow-to-use-libcurl-upload-stream-data-by-http-2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas