title: How to customize WRITEFUNCTION in libcurl to receive large data stream(up to 10K)?
body: <p>I want to customize my receive function for <code>libcurl</code> to receive large data(may be up to 10K).</p>
  
  <p>My current implementation is as below:</p>
  
  <pre><code>static size_t wt_callback(char *ptr, size_t size, size_t nmb,
          void *data) {
      int len = size * nmb;
  
      struct response *rsp = (struct response *)data;
      int byte = len &lt; rsp-&gt;buf_left ? len : rsp-&gt;buf_left;
      if (rsp-&gt;buf_offset == 0) {
          memset(rsp-&gt;buffer, 0, rsp-&gt;buf_left);
      }
      memcpy(rsp-&gt;buffer + rsp-&gt;buf_offset, ptr, byte);
      rsp-&gt;buf_offset += byte;
      rsp-&gt;buf_left   -= byte;
  
      return byte;
  }
  </code></pre>
  
  <p>and structure definition:</p>
  
  <pre><code>struct response {
      char *buffer;
      int  buf_left;
      int  buf_offset;
  };
  </code></pre>
  
  <p>I install the customized receive function:</p>
  
  <pre><code>curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wt_callback);
                                          /* How data is received */
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);
                                          /* Where to store incoming data */
  </code></pre>
  
  <p><code>response</code> is typed as <code>struct response *</code>.</p>
  
  <p>The current problem is the <code>wt_callback</code> function is not invoked, though I'm sure(I sniff the network with <code>wireshark</code>) that server responsed.</p>
  
  <p>I don't know where I'm trapped, or any problem with the receive function implementation. Any hint or suggestion will be highly appreciated.</p>
  
  <p>Thanks and Best regards.</p>