cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Having trouble getting http put to work using libcurl

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 11 Apr 2003 18:43:09 +0200 (CEST)

On Fri, 11 Apr 2003 david.prather_at_telelogic.com wrote:

> I'm having touble getting http put to work using the libcurl.dll (Windows).
> The file is created, but has zero size.

So what does curl_easy_perform() return?

> Uploading works fine however if I use the curl command-line tool.

This surely indicates a usage error.

> size_t readData(char *ptr, size_t size, size_t nmemb, void *userp)
> {
> if (0 == ptr || 0 == userp) {
> assert(0);
> return 0;
> }
> assert(size*nmemb != 0);
>
> std::istream* pIs = reinterpret_cast<std::istream*>(userp);
> int nLen = 0;
> char pszBuf[CURL_MAX_WRITE_SIZE];
> pIs->read(pszBuf, CURL_MAX_WRITE_SIZE);
> nLen = pIs->gcount();
> memcpy(ptr, pszBuf, nLen);
> return nLen;
> }

Aha! This code doesn't take into account how many bytes libcurl is asking
for. You must never return more data than it asks for, and it may not always
ask for a full CURL_MAX_WRITE_SIZE buffer. Hence the size and nmemb
arguments...

This will most likely return a different amount here than what libcurl passed
in, and that will be considered an error by the library and it'll bail out...

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
for complex code. Debugging C/C++ programs can leave you feeling lost and 
disoriented. TotalView can help you find your way. Available on major UNIX 
and Linux platforms. Try it free. www.etnus.com
Received on 2003-04-11