cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Info request about the zero copy interface

From: Legolas <legolas558_at_email.it>
Date: Sun, 04 Dec 2005 13:36:47 +0100

Daniel Stenberg ha scritto:

> On Thu, 1 Dec 2005, Legolas wrote:
>
>> A file-type object has DIFFERENT read and write callbacks from those
>> owned by a memory-type object. The object I was talking about in the
>> previous replies SETS them.
>
>
> Can you please write up a tiny client in a pseudo code using this new
> suggested API of yours? I still don't get how you get zero copy out of
> what you've explained.
>
I am very rusty in socket programming, I suppose you have the following
scenario when handling incoming data from the socket layer:

    - you have knowledge of a certain amount of pending data available
to be read through a
        function like 'recv'

    - libcurl currently handles an internal buffer to copy this data
into and caches several
        pending chunks into it to improve performance, calling the
associated write function
         callback on the internal buffer (but I am probably wrong about
this since such a
         scheme perhaps should not be the best)

Please correct my suppositions.

The basics of my previous explanations are these:

    - receive data into a temporary buffer if the client does not need to
        order chunks into a stream before using them (e.g. it may write
        them to file or do something else)

    - receive data into an assigned buffer if the client needs an ordered
       stream of data

Both cases can be handled by libcurl simply calling a write callback of
the following type:

void *write_buffer(void *custom_data, int desired_size);

Which returns the buffer pointer if *it is asserted* that the buffer is
_at least_ of the desired
size, else NULL if something goes wrong (CURLE_WRITE_ERROR).
My idea is to have the client handling the reallocation and I was
presenting you a possible
object which assigns its read/write methods automatically and that
automatically reallocates
its buffers. That's all.

Other readers' opinions are also welcome.

--
    Giuseppe
Received on 2005-12-04