You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Hracek, Petr" <pe...@siemens.com> on 2009/02/02 11:25:18 UTC

RE: Sending data to client

Thanks for example and explanation.

I've inserted to the my module ap_rvputs.
And this function returns me than number of bytes which has been send to 
the client was correct but the client (JAVA) does not get any data.
Shell I used ap_rflush in my code as well?

Has to be defined AP_FTYPE_* handler for working with filter data?

regards / S pozdravem
Petr Hráček

-----Original Message-----
From: Graham Leggett [mailto:minfrin@sharp.fm] 
Sent: Friday, January 30, 2009 1:27 PM
To: dev@httpd.apache.org
Subject: Re: Sending data to client

Hracek, Petr wrote:

> Because of I am a begginer with bucket and brigades
> Is there any short example how to send simple string to the client?
> I've found some examples but it were a pretty complicated for me.
> 
> E.g. http://www.apachetutor.org/dev/brigades 

Go through the underlying bucket brigade API here:

http://apr.apache.org/docs/apr-util/trunk/group___a_p_r___util___bucket___brigades.html

Essentially from your perspective, you want to create a brigade with 
apr_brigade_create(), and then create buckets, and put those buckets 
into the brigade.

When you want to flush the data, create a flush bucket, add it to the 
brigade, and give the brigade to the network using ap_pass_brigade(). 
You can call ap_pass_brigade as many times as you like (calling it 
excessively is inefficient though).

To create a flush bucket, use apr_bucket_flush_create.

There are convenience functions that allow you to add strings to a 
bucket brigade without having to create buckets from scratch:

apr_brigade_write
apr_brigade_writev
apr_brigade_printf
...etc

A note about what a bucket brigade is: a bucket_brigade is basically a 
linked list of pieces of data.

"Pieces of data" can be quite broad a definition. A piece of data might 
be a simple string, stored in a heap bucket. A "piece of data" might be 
a file on disk, stored in a file bucket.

The "piece of data" can also not be data at all, but rather a signal to 
do something special. A flush bucket is one example, and the EOS 
(end-of-stream) bucket is another that says "this is the last bucket in 
this response, you're done now".

The bucket brigade API is a bit mind bending at first, but it is a very 
valuable tool to use. If you want to write an Apache v2 filter, you'll 
need to know how the bucket brigades work, so they are definitely worth 
getting to understand.

Regards,
Graham
--