You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Christina Fu <fu...@gmail.com> on 2008/01/04 07:28:49 UTC
buffer in output filter
Hi,
Wish everyone a happy new year!
I am writing a connection type output filter and have a question about
the buffer. The filter reads a bucket, do some processing and put the
result into a stack buffer, create a transient bucket from it, add a
flush bucket and send to next filter.
Is it safe to use stack buffer (char out[8192]) here? since I added
flush bucket.
Is there any concern to flush frequently?
Performance wise, what is a good way to allocate "out" buffer? stack?
pool (what pool? if using c->pool, I was afraid it would take too much
buffer before the connection is closed and all pool memory freed)?, or
malloc? The bucket length range from a few bytes to 8K.
---------
const char *in;
apr_size_t inlen;
char out[8192];
int outlen;
//Read data from bucket
status = apr_bucket_read(bucket, &in, &inlen, APR_NONBLOCK_READ);
//process data and put into out buffer
process_data(in, inlen, out, &outlen);
//Create a transient bucket from out buffer
apr_bucket *bucket = apr_bucket_transient_create(out, outlen,
f->c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb, bucket);
//Create a flush bucket
apr_bucket *e = apr_bucket_flush_create(f->c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb, e);
//Pass to the next filter
ap_pass_brigade(f->next, bb);
----------
Appreciate any comments. Thanks a lot.
Christina