httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject Re: should input filter return the exact amount of bytes asked for?
Date Thu, 06 Nov 2003 11:49:33 GMT
Stas Bekman wrote:
> I'm trying to get rid of ap_get_client_block(), but I don't understand a 
> few things. ap_get_client_block() asks for readbytes from the upstream 
> filter. What happens if the filter returns less bytes (while there is 
> still more data coming?) What happens if the filter returns more bytes 
> than requested (e.g. because it uncompressed some data). After all the 
> incoming filters all propogate a request for N bytes read to the core_in 
> filter, which returns that exact number if it can. Now as the data flows 
> up the filter chain its length may change. Does it mean that if the 
> filter didn't return the exact amount asked for it's broken? Is that the 
> case when it returns less data than requested? Or when it returns more 
> data?
> I'm trying to deal with the case where a user call wants N bytes and 
> I've to give that exact number in a single call. I'm not sure whether I 
> should buffer things if I've got too much data or on the opposite ask 
> for more bbs if I don't have enough data. Are there any modules I can 
> look at to learn from?
> The doc for ap_get_brigade doesn't say anything about ap_get_brigade 
> satisfying 'readbytes' argument.
> /**
>  * Get the current bucket brigade from the next filter on the filter
>  * stack.  The filter returns an apr_status_t value.  If the bottom-most
>  * filter doesn't read from the network, then ::AP_NOBODY_READ is returned.
>  * The bucket brigade will be empty when there is nothing left to get.
>  * @param filter The next filter in the chain
>  * @param bucket The current bucket brigade.  The original brigade passed
>  *               to ap_get_brigade() must be empty.
>  * @param mode   The way in which the data should be read
>  * @param block  How the operations should be performed
>  *               ::APR_BLOCK_READ, ::APR_NONBLOCK_READ
>  * @param readbytes How many bytes to read from the next filter.
>  */
> AP_DECLARE(apr_status_t) ap_get_brigade(ap_filter_t *filter,
>                                         apr_bucket_brigade *bucket,
>                                         ap_input_mode_t mode,
>                                         apr_read_type_e block,
>                                         apr_off_t readbytes);

What bothers me most is the case where a filter may return more data than it 
has been asked for in the AP_MODE_READBYTES mode. ap_get_client_block() 
doesn't deal with buffering such data and drops it on the floor. So it either 
has to be fixed to do the buffering or the filter spec (ap_get_brigade) needs 
to clearly state that no more than requested amount of data should be returned 
in the AP_MODE_READBYTES. And ap_get_client_block needs to assert if it gets more.

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

View raw message