cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Read and Write callbacks

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 30 Jan 2010 16:50:32 +0100 (CET)

On Fri, 29 Jan 2010, vick wrote:

> I am trying to see how a read or write callback would work for chunked
> transfers. The prototypes have the sig:-
>
> Callback(void *ptr, size_t size, size_t nmemb, void *data)
>
> and it seems size*nmemb should be total bytes transferred (transferrable?).

To be exact: size*nmemb is the number of bytes passed in the particular
function invoke when it calls your function.

And if you by chunked transfer means a little piece at a time, that's always
how libcurl works.

> So if you are sending you have to keep track of the buffer position and feed
> it (size*nmemb) bytes at a time?

When sending, uploading, libcurl will call your read function and then libcurl
expects you to copy data to its buffer, but no more than size*nmemb bytes.

> And we can be sure that it will indeed send that many bytes, since curl
> would know the MTU of the network interfaces involved during connection
> negotiation and so on?

MTU has nothing to do with what libcurl asks for or not. It will ask for data
to make sure there is data in its buffer to have it ready when it is supposed
to send it. It will not sync its calling of the callbacks to any underlying
TCP states. When libcurl has sent all data you've given it before, it will ask
again for the next chunk and so on.

> And vice versa for recieving?

When receiving libcurl will call your function with data that it has received,
and you must take care of all of it and return to libcurl the amount of data
you did take care of.

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