cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: mmap & file uploads

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 1 Jun 2001 13:19:41 +0200 (MET DST)

On Thu, 31 May 2001, Sterling Hughes wrote:

> > Speaking of decreasing the amount copies when doing upload, we could very
> > well have a stab at downloads at the same time, right?

> I think I understand what you mean here, could you clarify it a little
> bit with some psuedo code of how this might work from a users point of
> view?

Okey, this is what I had in mind could be made to work. Never mind the exact
details, those are left to get smoothened out, should we decide we want
anything similar to this.

As was said before in this thread, the point would be to skip one level of
extra data copying (it does make things a little more complicated for the
user):

  /* tell libcurl what function to call when data has been delivered */
  curl_easy_setopt(CURLOPT_NOCOPY_DOWNLOAD_FUNCTION, my_write_callback);

  /* tell libcurl what function to call to get a buffer to store data in */
  curl_easy_setopt(CURLOPT_NOCOPY_GETBUF_FUNCTION, my_here_you_store_here);

  /* This function gets called before libcurl reads any data from the
     network, this function lets libcurl know where we want the data stored.
    */
  int my_here_you_store_here(void *clientp, size_t *sizep, void **bufp)
  {
    struct mystruct *my=clientp; /* application specific stuff */

    /* set the maximum amount of data we can read into this chunk */
    *sizep = my->size_left_to_fill_with_data;

    /* tell libcurl where we want the data stored */
    *bufp = my->pointer_to_where_we_want_data_filled_in;

    return OK_YOU_LIBCURL_YOU_MAY_PROCEDE_AND_DOWNLOAD_NOW;
  }

  /* This function get called when libcurl has written data to that place
     we previously told it to store data at. */
  int my_write_callback(void *clientp, size_t bytes_written, void *bufp)
  {
    struct mystruct *my=clientp;

    /* We advance our pointer where we want the next chunk of data */
    my->pointer_to_where_we_want_data_filled_in += bytes_written;

    /* We decrease the amount of data we have left in the buffer */
    my->size_left_to_fill_with_data -= bytes_written;

    return OK_WE_GOT_IT_NOW_CONTINUE;
  }

-- 
     Daniel Stenberg -- curl dude -- http://curl.haxx.se/
_______________________________________________
Curl-library mailing list
Curl-library_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library
Received on 2001-06-01