buffer_output(protocol.c)

server/protocol.c
static apr_status_t buffer_output(request_rec *r,
                                 const char *str, apr_size_t len)
{
   conn_rec *c = r->connection;
   ap_filter_t *f;
   old_write_filter_ctx *ctx;

   if (len == 0)
       return APR_SUCCESS;

   /* future optimization: record some flags in the request_rec to
    * say whether we've added our filter, and whether it is first.
    */

   /* this will typically exit on the first test */
   for (f = r->output_filters; f != NULL; f = f->next) {
       if (ap_old_write_func == f->frec)
           break;
   }

   if (f == NULL) {
       /* our filter hasn't been added yet */
       ctx = apr_pcalloc(r->pool, sizeof(*ctx));
       ap_add_output_filter("OLD_WRITE", ctx, r, r->connection);
       f = r->output_filters;
   }

   /* if the first filter is not our buffering filter, then we have to
    * deliver the content through the normal filter chain
    */
   if (f != r->output_filters) {
       apr_bucket_brigade *bb = apr_brigade_create(r->pool, c->bucket_alloc);
       apr_bucket *b = apr_bucket_transient_create(str, len, c->bucket_alloc);
       APR_BRIGADE_INSERT_TAIL(bb, b);

       return ap_pass_brigade(r->output_filters, bb);
   }

   /* grab the context from our filter */
   ctx = r->output_filters->ctx;

   if (ctx->bb == NULL) {
       ctx->bb = apr_brigade_create(r->pool, c->bucket_alloc);
   }

   return ap_fwrite(f->next, ctx->bb, str, len);
}
最終更新:2009年01月05日 22:44