Thank you Gisle & tetetest >From your replies I understand that the example code is correct and the >documentation is misleading. I will change my code to return the value returned by fwrite, which is the number of records written.
Avi Manor Airspan Networks Inc. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of [email protected] Sent: Thursday, March 29, 2012 12:00 PM To: [email protected] Subject: curl-library Digest, Vol 79, Issue 48 ---------------------------------------------------------------------- Message: 1 Date: Wed, 28 Mar 2012 12:59:13 +0200 From: Gisle Vanem <[email protected]> To: libcurl development <[email protected]> Subject: Re: ftpget.c example error Message-ID: <[email protected]> Content-Type: text/plain; CHARSET=US-ASCII; format=flowed; reply-type=original "Avi Manor" <[email protected]> wrote: Please don't post in html. It's messy to format a sensible reply in html. > While testing this example I have noticed that every call to my_fwrite comes > with size = 1. > This is the reason why the error is unnoticeable. However, it is not > guaranteed to get every call with size = 1. 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? --gv ------------------------------ Message: 2 Date: Wed, 28 Mar 2012 17:27:35 +0400 From: tetetest tetetest <[email protected]> To: libcurl development <[email protected]> Subject: Re: ftpget.c example error Message-ID: <[email protected]> Content-Type: text/plain; charset="us-ascii"; format="flowed" * Gisle Vanem <[email protected]> [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
