cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Advanced API?

From: Andrew Francis <locust_at_familyhealth.com.au>
Date: Thu, 18 Oct 2001 14:17:05 +0800

> We should write down the functions, document their expected behavior
and we
> could try writing some faked implementation of clients using it. Then
it'll
> be easier to implement the API. IMHO.

I have an application which receives a stream of data in the form
HEADER, DATA, HEADER, DATA... the header is a constant size, the size of
the data is determined by information in the header.

At the moment I have a callback function that does it's own buffering -
if it's expecting n bytes, and there's
less than that available, it takes what it can and buffers it. When it
gets enough information, it hands the entire HEADER/DATA off to a
separate function for processing.

What I'd really like to see is the ability to handle this "I want to
wait until I have this much data available" behaviour with curl. Maybe
something like the following:

  curl_connect(cp);
  expecting_data = MY_HEADER_SIZE;
  while(expecting_data > 0) {
    int status = curl_wait_for_data(expecting_data);
    if(status != READY_TO_READ) {
      // spew dire error messages here
      expecting_data = 0;
    } else {
      curl_read(cp, buffer, expecting_data);
      // process the data in buffer and set expecting_data to the size
of the next block,
      // or zero to finish
    }
  }

What do people think?

--
Andrew Francis
locust_at_familyhealth.com.au
Received on 2001-10-18