httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Stein <gst...@lyra.org>
Subject Re: PLEASE READ: Filter I/O
Date Fri, 23 Jun 2000 18:42:54 GMT
On Fri, Jun 23, 2000 at 12:30:02PM -0500, William A. Rowe, Jr. wrote:
>...
> What about passing buf, buflen, alloc, alloclen on?  That way we don't need
> to do any realloc if we are growing the buffer by 10 chars and the last 
> filter just chopped the buffer by 50 chars?

No can do. The buffer that is passed to the (link-based) filter callback is
constant. There is no "growing of the buffer" since it is inviolate.

>...
> would be the simple example of stripping of 5 bytes.  But this sounds
> like a hook-based link-list to me (since ap_lwrite needs to parse where
> layer is in the stack and kick to the next), rather than a simple hook
> based where 
> 
> ap_status_t my_filter_callback(ap_layer_t **layer, const void 
> 					 *buf, size_t len)
> 					 *abuf, size_t alen) {
>      /* **layer is us */
>      return ap_lwrite(layer + 1, buf + 5, len - 5, abuf, alen);
> }

Each callback is passed an ap_layer_t which represents that filter. There is
a next pointer inside which is used by ap_lwrite().  Example:

typedef struct ap_layer_t ap_layer_t;
struct ap_layer_t {
    ap_status_t (*callback)(ap_layer_t *layer, const char *buf, size_t len);
    void *ctx;
    request_rec *r;
    ap_layer_t *next;
};

ap_status_t ap_lwrite(ap_layer_t *layer, const char *buf, size_t len)
{
    if (layer->next == NULL)
        return ap_bwrite(layer->r->connection->client, buf, len);

    return (*layer->next->callback)(layer->next, buf, len);
}


Pretty simple, and it hides the notion of "next" from the filter callback.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Mime
View raw message