Ejemplo n.º 1
0
void nghttp2_bufs_reset(nghttp2_bufs *bufs)
{
  nghttp2_buf_chain *chain, *ci;
  size_t k;

  k = bufs->chunk_keep;

  for(ci = bufs->head; ci; ci = ci->next) {
    nghttp2_buf_reset(&ci->buf);
    nghttp2_buf_shift_right(&ci->buf, bufs->offset);

    if(--k == 0) {
      break;
    }
  }

  if(ci) {
    chain = ci->next;
    ci->next = NULL;

    for(ci = chain; ci;) {
      chain = ci->next;

      buf_chain_del(ci);

      ci = chain;
    }

    bufs->chunk_used = bufs->chunk_keep;
  }

  bufs->cur = bufs->head;
}
Ejemplo n.º 2
0
ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out)
{
  size_t len;
  nghttp2_buf_chain *chain;
  nghttp2_buf *buf;
  uint8_t *res;
  nghttp2_buf resbuf;

  len = 0;

  for(chain = bufs->head; chain; chain = chain->next) {
    len += nghttp2_buf_len(&chain->buf);
  }

  if(!len) {
    res = NULL;
  } else {
    res = (uint8_t *)malloc(len);

    if(res == NULL) {
      return NGHTTP2_ERR_NOMEM;
    }
  }

  nghttp2_buf_wrap_init(&resbuf, res, len);

  for(chain = bufs->head; chain; chain = chain->next) {
    buf = &chain->buf;

    if(resbuf.last) {
      resbuf.last = nghttp2_cpymem(resbuf.last,
                                   buf->pos, nghttp2_buf_len(buf));
    }

    nghttp2_buf_reset(buf);
    nghttp2_buf_shift_right(&chain->buf, bufs->offset);
  }

  bufs->cur = bufs->head;

  *out = res;

  return (ssize_t)len;
}
Ejemplo n.º 3
0
void nghttp2_bufs_reset(nghttp2_bufs *bufs) {
  nghttp2_buf_chain *chain, *ci;
  size_t k;

  k = bufs->chunk_keep;

  for (ci = bufs->head; ci; ci = ci->next) {
    nghttp2_buf_reset(&ci->buf);
    nghttp2_buf_shift_right(&ci->buf, bufs->offset);

    // h1994st:
    if (bufs->random_enabled) {
      // Resize each kept chunk
      hx_nghttp2_buf_resize(&ci->buf, hx_get_buf_chunk_length(bufs->buf_chunk_length_gen));
    }

    if (--k == 0) {
      break;
    }
  }

  if (ci) {
    chain = ci->next;
    ci->next = NULL;

    for (ci = chain; ci;) {
      chain = ci->next;

      buf_chain_del(ci, bufs->mem);

      ci = chain;
    }

    bufs->chunk_used = bufs->chunk_keep;
  }

  bufs->cur = bufs->head;
}