cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: ftpget.c example error

From: tetetest tetetest <tetetest_at_rambler.ru>
Date: Wed, 28 Mar 2012 17:27:35 +0400

* Gisle Vanem <gvanem_at_broadpark.no> [Wed, 28 Mar 2012 12:59:13 +0200]:

> Why not? AFAICS, 'data->set.fwrite_func()' is always called with
> 'size=1'.
> Ref. sendf.c line 456. Can you figure out where your callback is
called
> from? And on what OS and libcurl version do you see this behavior?

Write callback function is modelled after standard C function fwrite(),
so it should behave identically. In particular, we should not make any
assumptions about the size of the record passed to callback, because
it can change in the future.

The documentation for CURLOPT_WRITEFUNCTION is a bit misleading:

"CURLOPT_WRITEFUNCTION

Function pointer that should match the following prototype:
size_t function( char *ptr, size_t size, size_t nmemb, void *userdata);
This function gets called by libcurl as soon as there is data received
that
needs to be saved. The size of the data pointed to by ptr is size
multiplied
with nmemb, it will not be zero terminated."

Here a short explanation of the parameters is desirable, like: "Here
'size'
is the size of a record, and 'nmemb' is the number of records to
handle".

And the next passage is utterly misleading:
"Return the number of bytes actually taken care of. If that amount
differs
from the amount passed to your function, it'll signal an error to the
library. This will abort the transfer and return CURLE_WRITE_ERROR."

In fact, fwrite() is supposed to return the number of records written,
not
bytes. Thus, the passage must be changed to something like:

"Return the number of records actually taken care of. If that number
differs from the amount passed to your function in nmemb, it'll signal
an error to the library. This will abort the transfer and return
CURLE_WRITE_ERROR. "

--
tetetest tetetest.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-03-28