Show
Ignore:
Timestamp:
09/16/09 04:17:11 (9 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253074631 +0000
git-parent:

[202f85178854db96b302a656508cc591b67a143e]

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

fix the request fetching stuff

Files:

Legend:

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

    r003a683 r6298e33  
    262262 match: 
    263263  req->current_request_chain = req->first_input; 
     264  noitL(noit_debug, " noit_http_request_finalize : match(%d in %d)\n", 
     265        req->current_offset - req->current_input->start, 
     266        req->current_input->size); 
    264267  if(req->current_offset < 
    265268     req->current_input->start + req->current_input->size) { 
    266269    /* There are left-overs */ 
    267     req->first_input = bchain_alloc(MAX(DEFAULT_BCHAINSIZE, 
    268                                         req->current_input->size)); 
     270    int lsize = req->current_input->size - req->current_offset; 
     271    noitL(noit_debug, " noit_http_request_finalize -- leftovers: %d\n", lsize); 
     272    req->first_input = bchain_alloc(lsize); 
    269273    req->first_input->prev = NULL; 
    270274    req->first_input->next = req->current_input->next; 
    271275    req->first_input->start = 0; 
    272     req->first_input->size = req->current_input->size - (req->current_offset + req->current_input->start)
     276    req->first_input->size = lsize
    273277    memcpy(req->first_input->buff, 
    274            req->current_input->buff + 
    275              req->current_input->start + req->current_offset, 
     278           req->current_input->buff + req->current_offset, 
    276279           req->first_input->size); 
    277280    if(req->last_input == req->current_input) 
    278281      req->last_input = req->first_input; 
     282    else 
     283      bchain_free(req->current_input); 
    279284  } 
    280285  else { 
     
    417422  if(err == noit_true) goto full_error; 
    418423 
    419   in = ctx->req.last_input; 
    420   if(!in) { 
    421     in = ctx->req.first_input = ctx->req.last_input = 
    422       bchain_alloc(DEFAULT_BCHAINSIZE); 
    423     if(!in) goto full_error; 
    424   } 
    425424  while(1) { 
    426425    int len; 
    427426 
     427    in = ctx->req.last_input; 
     428    if(!in) { 
     429      in = ctx->req.first_input = ctx->req.last_input = 
     430        bchain_alloc(DEFAULT_BCHAINSIZE); 
     431      if(!in) goto full_error; 
     432    } 
    428433    if(in->size > 0 && /* we've read something */ 
    429434       DEFAULT_BCHAINMINREAD > BCHAIN_SPACE(in) && /* we'd like read more */ 
     
    440445                                   in->allocd - in->size - in->start, 
    441446                                   &mask, ctx->conn.e); 
     447    noitL(noit_debug, " noit_http -> read(%d) = %d\n", ctx->conn.e->fd, len); 
    442448    if(len == -1 && errno == EAGAIN) return mask; 
    443449    if(len <= 0) goto full_error; 
     
    507513  /* We attempt to consume from the first_input */ 
    508514  struct bchain *in, *tofree; 
     515  noitL(noit_debug, " ... noit_http_session_req_consume(%d) %d of %d\n", 
     516        ctx->conn.e->fd, len, 
     517        ctx->req.content_length - ctx->req.content_length_read); 
    509518  len = MIN(len, ctx->req.content_length - ctx->req.content_length_read); 
    510519  while(bytes_read < len) { 
     
    516525      bytes_read += partial_len; 
    517526      ctx->req.content_length_read += partial_len; 
     527      noitL(noit_debug, " ... filling %d bytes (read through %d/%d)\n", 
     528            bytes_read, ctx->req.content_length_read, ctx->req.content_length); 
    518529      in->start += partial_len; 
    519530      in->size -= partial_len; 
     
    525536        if(in == NULL) { 
    526537          ctx->req.last_input = NULL; 
     538          noitL(noit_debug, " ... noit_http_session_req_consume = %d\n", 
     539                bytes_read); 
    527540          return bytes_read; 
    528541        } 
     
    544557                                      in->allocd - in->size - in->start, 
    545558                                      mask, ctx->conn.e); 
     559      noitL(noit_debug, " noit_http -> read(%d) = %d\n", ctx->conn.e->fd, rlen); 
    546560      if(rlen == -1 && errno == EAGAIN) { 
    547          /* We'd block to read more, but we have data, 
    548           * so do a short read */ 
    549          if(ctx->req.first_input->size) break; 
    550          /* We've got nothing... */ 
    551          return -1; 
     561        /* We'd block to read more, but we have data, 
     562         * so do a short read */ 
     563        if(ctx->req.first_input->size) break; 
     564        /* We've got nothing... */ 
     565        noitL(noit_debug, " ... noit_http_session_req_consume = -1 (EAGAIN)\n"); 
     566        return -1; 
    552567      } 
    553       if(rlen <= 0) return -1; 
     568      if(rlen <= 0) { 
     569        noitL(noit_debug, " ... noit_http_session_req_consume = -1 (error)\n"); 
     570        return -1; 
     571      } 
    554572      in->size += rlen; 
    555573      crlen += rlen; 
     
    570588   * noted that in noit_http_request_release. 
    571589   */ 
     590  noitL(noit_debug, " -> noit_http_session_drive(%d) [%x]\n", e->fd, origmask); 
    572591  while(ctx->drainage > 0) { 
    573592    int len; 
     593    noitL(noit_debug, "   ... draining last request(%d)\n", e->fd); 
    574594    len = noit_http_session_req_consume(ctx, NULL, ctx->drainage, &mask); 
    575     if(len == -1 && errno == EAGAIN) return mask; 
     595    if(len == -1 && errno == EAGAIN) { 
     596      noitL(noit_debug, " <- noit_http_session_drive(%d) [%x]\n", e->fd, mask); 
     597      return mask; 
     598    } 
    576599    if(len <= 0) goto abort_drive; 
    577600    ctx->drainage -= len; 
     
    581604  if(ctx->req.complete != noit_true) { 
    582605    int maybe_write_mask; 
     606    noitL(noit_debug, "   -> noit_http_complete_request(%d)\n", e->fd); 
    583607    mask = noit_http_complete_request(ctx, origmask); 
     608    noitL(noit_debug, "   <- noit_http_complete_request(%d) = %d\n", 
     609          e->fd, mask); 
    584610    _http_perform_write(ctx, &maybe_write_mask); 
    585611    if(ctx->conn.e == NULL) goto release; 
    586     if(ctx->req.complete != noit_true) return mask | maybe_write_mask; 
     612    if(ctx->req.complete != noit_true) { 
     613      noitL(noit_debug, " <- noit_http_session_drive(%d) [%x]\n", e->fd, 
     614            mask|maybe_write_mask); 
     615      return mask | maybe_write_mask; 
     616    } 
    587617  } 
    588618 
    589619  /* only dispatch if the response is not complete */ 
    590   if(ctx->res.complete == noit_false) rv = ctx->dispatcher(ctx); 
     620  if(ctx->res.complete == noit_false) { 
     621    noitL(noit_debug, "   -> dispatch(%d)\n", e->fd); 
     622    rv = ctx->dispatcher(ctx); 
     623    noitL(noit_debug, "   <- dispatch(%d) = %d\n", e->fd, rv); 
     624  } 
    591625 
    592626  _http_perform_write(ctx, &mask); 
     
    606640  if(ctx->req.complete == noit_false) goto next_req; 
    607641  if(ctx->conn.e) { 
     642    noitL(noit_debug, " <- noit_http_session_drive(%d) [%x]\n", e->fd, mask|rv); 
    608643    return mask | rv; 
    609644  } 
     645  noitL(noit_debug, " <- noit_http_session_drive(%d) [%x]\n", e->fd, 0); 
    610646  return 0; 
    611647 release: 
    612648  noit_http_ctx_session_release(ctx); 
     649  noitL(noit_debug, " <- noit_http_session_drive(%d) [%x]\n", e->fd, 0); 
    613650  return 0; 
    614651}