cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Re: libcurl/ download buffer size is different to upload buffer size.

From: Keonwoo Kim <kkw0528_at_gmail.com>
Date: Thu, 29 Jan 2015 17:16:22 +0900

Thank you for your reply.

*>> I'm using the curl-7.3.0 to upload and download file to openstack
swift. *

>I think you meant something else. We never released any version called
7.3.0.

it is misspelled, I'm using the curl-7.30.0.

*>> very small file download is well operated. but when more size(1~100MB)
file *
*>> downloads, the size of receive buffer is about 1 KB (It is too small. I
know *
*>> that default buffer size is 16KB). *

>The receive buffer is always the same 16KB size unless you rebuild libcurl
>with a custom size. And it doesn't matter how fast you download things,
>libcurl uses the same buffer (size).

I tried to rebuild libcurl with a custom buffer size. but receive
buffer(size * nmemb) is too small..(1300 ~ 1400 bytes)

*>> it occurs timeout problem because write callback function is
frequently *
*>> called. *

>Is your write callback very slow? Cause otherwise it should not be a
problem
>that the callback is called often. libcurl reads as much as possible (into
the
>given buffer) and then sends it to the callback.

I just used callback function in libcurl official page (getinmemory.c
<http://github.com/bagder/curl/raw/master/docs/examples/getinmemory.c>)..

=======================callback code=========================

static size_t WriteMemoryCallback(void *contents, size_t size, size_t
nmemb, void *userp)

{

  size_t realsize = size * nmemb;

  struct MemoryStruct *mem = (struct MemoryStruct *)userp;

  printf("buff size: %zu\n", size * nmemb);

  mem->memory = realloc(mem->memory, mem->size + realsize + 1);

  if(mem->memory == NULL) {

    /* out of memory! */

    printf("not enough memory (realloc returned NULL)\n");

    return 0;

  }

  memcpy(&(mem->memory[mem->size]), contents, realsize);

  mem->size += realsize;

  mem->memory[mem->size] = 0;

  return realsize;

}
=====================================================================

=========================set option code ================================
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
  curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);

  curl_easy_setopt(curl_handle, CURLOPT_BUFFERSIZE, CURL_MAX_WRITE_SIZE);
  /* send all data to this function */
  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

  /* we pass our 'chunk' struct to the callback function */
  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

  /* some servers don't like requests that are made without a user-agent
     field, so we provide one */
  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
  curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 3);
  curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 3);
======================================================================

As you said..

Isn't it a libcurl problem? but server-side problem, network environment or
...

*>> When I used cURL command to download same file, file download speed is
very *
*>> fast.. *

>And that uses the same buffer size which would rather indicate that the
>problem you see is due to something your program is adding to the mix?

Thank you for your reply.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-01-29