httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject cvs commit: httpd-2.0/modules/filters mod_deflate.c
Date Tue, 07 May 2002 00:35:16 GMT
jerenkrantz    02/05/06 17:35:16

  Modified:    modules/filters mod_deflate.c
  Log:
  Add DeflateBufferSize directive to replace hardcoded FILTER_BUFSIZE
  definition.  Also speeds up ctx init since it takes the buffer and does
  a malloc rather than a calloc on it.
  
  Revision  Changes    Path
  1.3       +26 -7     httpd-2.0/modules/filters/mod_deflate.c
  
  Index: mod_deflate.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/filters/mod_deflate.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- mod_deflate.c	6 May 2002 23:37:15 -0000	1.2
  +++ mod_deflate.c	7 May 2002 00:35:16 -0000	1.3
  @@ -126,13 +126,14 @@
   {
       int windowSize;
       int memlevel;
  +    int bufferSize;
       char *noteName;
   } deflate_filter_config;
   
   /* windowsize is negative to suppress Zlib header */
   #define DEFAULT_WINDOWSIZE -15
   #define DEFAULT_MEMLEVEL 9
  -#define FILTER_BUFSIZE 8096
  +#define DEFAULT_BUFFERSIZE 8096
   
   /* Outputs a long in LSB order to the given file
    * only the bottom 4 bits are required for the deflate file format.
  @@ -152,6 +153,7 @@
   
       c->memlevel   = DEFAULT_MEMLEVEL;
       c->windowSize = DEFAULT_WINDOWSIZE;
  +    c->bufferSize = DEFAULT_BUFFERSIZE;
   
       return c;
   }
  @@ -173,6 +175,20 @@
       return NULL;
   }
   
  +static const char *deflate_set_buffer_size(cmd_parms *cmd, void *dummy,
  +                                           const char *arg)
  +{
  +    deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
  +                                                    &deflate_module);
  +
  +    c->bufferSize = atoi(arg);
  +
  +    if (c->bufferSize <= 0) {
  +        return "DeflateBufferSize should be positive";
  +    }
  +
  +    return NULL;
  +}
   static const char *deflate_set_note(cmd_parms *cmd, void *dummy,
                                       const char *arg)
   {
  @@ -206,7 +222,7 @@
   typedef struct deflate_ctx_t
   {
       z_stream stream;
  -    unsigned char buffer[FILTER_BUFSIZE];
  +    unsigned char *buffer;
       unsigned long crc;
       apr_bucket_brigade *bb;
   } deflate_ctx;
  @@ -280,6 +296,7 @@
           /* We're cool with filtering this. */
           ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
           ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
  +        ctx->buffer = apr_palloc(r->pool, c->bufferSize);
   /*
           ctx->stream.zalloc = (alloc_func) 0;
           ctx->stream.zfree = (free_func) 0;
  @@ -324,7 +341,7 @@
   
               ctx->stream.avail_in = 0; /* should be zero already anyway */
               for (;;) {
  -                deflate_len = FILTER_BUFSIZE - ctx->stream.avail_out;
  +                deflate_len = c->bufferSize - ctx->stream.avail_out;
   
                   if (deflate_len != 0) {
                       b = apr_bucket_heap_create((char *)ctx->buffer,
  @@ -332,7 +349,7 @@
                                                  f->c->bucket_alloc);
                       APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
                       ctx->stream.next_out = ctx->buffer;
  -                    ctx->stream.avail_out = FILTER_BUFSIZE;
  +                    ctx->stream.avail_out = c->bufferSize;
                   }
   
                   if (done) {
  @@ -420,17 +437,17 @@
                                                         * trust zlib */
           ctx->stream.avail_in = len;
           ctx->stream.next_out = ctx->buffer;
  -        ctx->stream.avail_out = FILTER_BUFSIZE;
  +        ctx->stream.avail_out = c->bufferSize;
   
           while (ctx->stream.avail_in != 0) {
               if (ctx->stream.avail_out == 0) {
                   ctx->stream.next_out = ctx->buffer;
  -                len = FILTER_BUFSIZE - ctx->stream.avail_out;
  +                len = c->bufferSize - ctx->stream.avail_out;
   
                   b = apr_bucket_heap_create((char *)ctx->buffer, len,
                                              NULL, f->c->bucket_alloc);
                   APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
  -                ctx->stream.avail_out = FILTER_BUFSIZE;
  +                ctx->stream.avail_out = c->bufferSize;
               }
   
               zRC = deflate(&(ctx->stream), Z_NO_FLUSH);
  @@ -455,6 +472,8 @@
                     "Set a note to report on compression ratio"),
       AP_INIT_TAKE1("DeflateWindowSize", deflate_set_window_size, NULL,
                     RSRC_CONF, "Set the Deflate window size (1-15)"),
  +    AP_INIT_TAKE1("DeflateBufferSize", deflate_set_buffer_size, NULL, RSRC_CONF,
  +                  "Set the Deflate Buffer Size"),
       AP_INIT_TAKE1("DeflateMemLevel", deflate_set_memlevel, NULL, RSRC_CONF,
                     "Set the Deflate Memory Level (1-9)"),
       {NULL}
  
  
  

Mime
View raw message