Show
Ignore:
Timestamp:
07/17/10 23:49:26 (8 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1279410566 +0000
git-parent:

[a098b4f6a6c538302bdb0866d1afd4c9c3a656d0]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1279410566 +0000
Message:

hack to allow un-dup'd mmap buckets to be sent over HTTP when the planets align (no chunks, no compression)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_http.c

    rea766cf r68a5668  
    3939#include <assert.h> 
    4040#include <zlib.h> 
     41#include <sys/mman.h> 
    4142#include <libxml/tree.h> 
    4243 
     
    7980struct bchain *bchain_alloc(size_t size, int line) { 
    8081  struct bchain *n; 
    81   n = malloc(size + (int)((char *)((struct bchain *)0)->buff)); 
     82  n = malloc(size + offsetof(struct bchain, _buff)); 
    8283  /*noitL(noit_error, "bchain_alloc(%p) : %d\n", n, line);*/ 
    8384  if(!n) return NULL; 
     
    8586  n->start = n->size = 0; 
    8687  n->allocd = size; 
     88  n->buff = n->_buff; 
     89  return n; 
     90} 
     91struct bchain *bchain_mmap(int fd, size_t len, int flags, off_t offset) { 
     92  struct bchain *n; 
     93  void *buff; 
     94  buff = mmap(NULL, len, PROT_READ, flags, fd, offset); 
     95  if(buff == MAP_FAILED) return NULL; 
     96  n = bchain_alloc(0, 0); 
     97  n->type = BCHAIN_MMAP; 
     98  n->buff = buff; 
     99  n->size = len; 
     100  n->allocd = len; 
    87101  return n; 
    88102} 
    89103void bchain_free(struct bchain *b, int line) { 
    90104  /*noitL(noit_error, "bchain_free(%p) : %d\n", b, line);*/ 
     105  if(b->type == BCHAIN_MMAP) { 
     106    munmap(b->buff, b->allocd); 
     107  } 
    91108  free(b); 
    92109} 
     
    233250_http_perform_write(noit_http_session_ctx *ctx, int *mask) { 
    234251  int len, tlen = 0; 
     252  size_t attempt_write_len; 
    235253  struct bchain **head, *b; 
    236254 choose_bucket: 
     
    257275  } 
    258276 
     277  attempt_write_len = b->size - ctx->res.output_raw_offset; 
     278  attempt_write_len = MIN(attempt_write_len, ctx->max_write); 
     279 
    259280  len = ctx->conn.e->opset-> 
    260281          write(ctx->conn.e->fd, 
    261282                b->buff + b->start + ctx->res.output_raw_offset, 
    262                 b->size - ctx->res.output_raw_offset, 
    263                 mask, ctx->conn.e); 
     283                attempt_write_len, mask, ctx->conn.e); 
    264284  if(len == -1 && errno == EAGAIN) { 
    265285    *mask |= EVENTER_EXCEPTION; 
     
    775795  ctx->req.complete = noit_false; 
    776796  ctx->conn.e = e; 
     797  ctx->max_write = DEFAULT_MAXWRITE; 
    777798  ctx->dispatcher = f; 
    778799  ctx->dispatcher_closure = c; 
     
    877898    o = ctx->res.output; 
    878899    while(o->next) o = o->next; 
     900    o->allocd = o->size; /* so we know it is full */ 
    879901    o->next = b; 
    880902    b->prev = o; 
    881903  } 
    882904  return noit_true; 
     905} 
     906noit_boolean 
     907noit_http_response_append_mmap(noit_http_session_ctx *ctx, 
     908                               int fd, size_t len, int flags, off_t offset) { 
     909  struct bchain *n; 
     910  n = bchain_mmap(fd, len, flags, offset); 
     911  if(n == NULL) return noit_false; 
     912  return noit_http_response_append_bchain(ctx, n); 
    883913} 
    884914static int 
     
    9911021  int opts = ctx->res.output_options; 
    9921022 
     1023  if(in->type == BCHAIN_MMAP && 
     1024     0 == (opts & (NOIT_HTTP_GZIP | NOIT_HTTP_DEFLATE | NOIT_HTTP_CHUNKED))) { 
     1025    out = ALLOC_BCHAIN(0); 
     1026    out->buff = in->buff; 
     1027    out->type = in->type; 
     1028    out->size = in->size; 
     1029    out->allocd = in->allocd; 
     1030    in->type = BCHAIN_INLINE; 
     1031    return out; 
     1032  } 
    9931033  /* a chunked header looks like: hex*\r\ndata\r\n */ 
    9941034  /* let's assume that content never gets "larger" */