httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Erenkrantz <jus...@erenkrantz.com>
Subject Re: Replacing ap_get_client_block with ap_get_brigade
Date Tue, 20 May 2003 15:40:08 GMT
--On Tuesday, May 20, 2003 9:06 AM -0400 "P. Dwayne Miller" 
<dmiller@espgroup.net> wrote:

> This may be a little off topic for this list, but I'll ask anyway.  Feel
> free to redirect me to the proper list.

Nah, this is on-topic.  =)

> Has anyone written a how-to, or documented the steps required to migrate a
> module from using the *client_block* calls with the appropriate *brigade*
> calls?
>
> I currently see the following calls used by the module (not necessarily in
> this order):
>
> return ap_setup_client_block(r, REQUEST_CHUNKED_ERROR);
> return ap_should_client_block(r);
> return ap_get_client_block(r, contentbuff, len);

Something like the following might work:

apr_bucket_brigade *brigade;
int seen_eos;

brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
seen_eos = 0;

while (!seen_eos) {
    apr_status_t rv;
    apr_bucket *e;

    /* len is how many bytes you want to read at most in one call. */
    rv = ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES,
                        APR_BLOCK_READ, len);
    if (rv != APR_SUCCESS) {
       /* Something bad happened. */
       return rv;
    }

    while (!APR_BRIGADE_EMPTY(brigade)) {
       apr_bucket *bucket;
       const char *data;
       apr_size_t *data_len;

       bucket = APR_BRIGADE_FIRST(brigade);

       if (APR_BUCKET_IS_EOS(bucket)) {
            /* We've hit the end!  Stop!  */
            seen_eos = 1;
            break;
       }

       rv = apr_bucket_read(bucket, &data, &data_len, APR_BLOCK_READ);
       if (rv != APR_SUCCESS) {
            return rv;
       }
       /* You are now free to do whatever you want with data.  It's a char*
        * with a length of data_len.  Treat this the same as what you got back
        * from ap_get_client_block().
        */
       apr_bucket_delete(bucket);
    }
}

This is off the top of my head, but this is roughly how I'd do it.

Good luck.  =)  -- justin

Mime
View raw message