curl-library
Re: working on a new API
Date: Sat, 27 Oct 2001 02:54:45 -0700
/* tells user about new data. Daniel's note (26-oct-2001): Why would we
* neeed a separate callback function? We have callback functions in
all the
* single curl_handles already that should be called for reading/writing
* data, right? */
curl_select_callback(select_handle, function, void*);
You're right.
/* suggested functions. Daniel's note: I'm not sure they add any real
* value. Do they? */
curl_select_readsize(select_handle, int);
curl_select_writesize(select_handle, int);
I was thinking it would set the max read & write size per select_perform
call. This might make more sense as a curl_handle call too. I was
thinking it would be usefull for large transfers. For example, if you're
sending a 200M file, you're not going to dump the whole thing into your
socket buffer in one pass.
/***************************************************************
*
* A tiny example application that downloads one HTTP page while
* uploading a FTP file!
*
* (psuedo C code)
*
**********************************/
FILE *writehere = fopen("dump", "w");
FILE *readfrom = fopen("upload", "r");
/* setup the HTTP download */
http_handle = curl_easy_init();
curl_easy_setopt(http_handle, CURLOPT_URL, "http://http.com/html");
curl_easy_setopt(http_handle, CURLOPT_FILE, writehere);
curl_easy_setopt(http_handle, CALLBACK, my_handle_callback);
curl_easy_setopt(http_handle, CURLOPT_BLOCKING, 0);
/* setup the FTP upload */
ftp_handle = curl_easy_init();
curl_easy_setopt(ftp_handle, CURLOPT_URL, "ftp://ftp.com/uploadfile");
curl_easy_setopt(ftp_handle, CURLOPT_INFILE, readhere);
curl_easy_setopt(ftp_handle, CALLBACK, my_handle_callback);
curl_easy_setopt(ftp_handle, CURLOPT_BLOCKING, 0);
/* create a select handle */
select_handle = curl_select_cleanup();
curl_select_add_handle(select_handle, http_handle);
curl_select_add_handle(select_handle, ftp_handle);
I was thinking this middle bit would look like:
{
while(curl_select_count(select_handle)!=0)
{ curl_select_perform(select_handle); }
/* this way curl_select_extract isn't needed */
}
void my_handle_callback(curl_handle, message, data)
{
if (message == FINISHED)
{ curl_select_remove_handle(select_handle, curl_handle); }
/* maybe curl_select_perform should take care of removing the
handle? */
}
curl_select_cleanup(select_handle);
curl_easy_cleanup(ftp_handle);
curl_easy_cleanup(http_handle);
We'll also need a call like curl_easy_perform(curl_handle) that is
non-blocking that is called from within
curl_select_perform(curl_select_handle) on sockets with data.
Received on 2001-10-27