Lines Matching refs:q
230 static void bufq_init(struct bufq *q, struct bufc_pool *pool, in bufq_init() argument
235 memset(q, 0, sizeof(*q)); in bufq_init()
236 q->chunk_size = chunk_size; in bufq_init()
237 q->max_chunks = max_chunks; in bufq_init()
238 q->pool = pool; in bufq_init()
239 q->opts = opts; in bufq_init()
242 void Curl_bufq_init2(struct bufq *q, size_t chunk_size, size_t max_chunks, in Curl_bufq_init2() argument
245 bufq_init(q, NULL, chunk_size, max_chunks, opts); in Curl_bufq_init2()
248 void Curl_bufq_init(struct bufq *q, size_t chunk_size, size_t max_chunks) in Curl_bufq_init() argument
250 bufq_init(q, NULL, chunk_size, max_chunks, BUFQ_OPT_NONE); in Curl_bufq_init()
253 void Curl_bufq_initp(struct bufq *q, struct bufc_pool *pool, in Curl_bufq_initp() argument
256 bufq_init(q, pool, pool->chunk_size, max_chunks, opts); in Curl_bufq_initp()
259 void Curl_bufq_free(struct bufq *q) in Curl_bufq_free() argument
261 chunk_list_free(&q->head); in Curl_bufq_free()
262 chunk_list_free(&q->spare); in Curl_bufq_free()
263 q->tail = NULL; in Curl_bufq_free()
264 q->chunk_count = 0; in Curl_bufq_free()
267 void Curl_bufq_reset(struct bufq *q) in Curl_bufq_reset() argument
270 while(q->head) { in Curl_bufq_reset()
271 chunk = q->head; in Curl_bufq_reset()
272 q->head = chunk->next; in Curl_bufq_reset()
273 chunk->next = q->spare; in Curl_bufq_reset()
274 q->spare = chunk; in Curl_bufq_reset()
276 q->tail = NULL; in Curl_bufq_reset()
279 size_t Curl_bufq_len(const struct bufq *q) in Curl_bufq_len() argument
281 const struct buf_chunk *chunk = q->head; in Curl_bufq_len()
290 size_t Curl_bufq_space(const struct bufq *q) in Curl_bufq_space() argument
293 if(q->tail) in Curl_bufq_space()
294 space += chunk_space(q->tail); in Curl_bufq_space()
295 if(q->spare) { in Curl_bufq_space()
296 struct buf_chunk *chunk = q->spare; in Curl_bufq_space()
302 if(q->chunk_count < q->max_chunks) { in Curl_bufq_space()
303 space += (q->max_chunks - q->chunk_count) * q->chunk_size; in Curl_bufq_space()
308 bool Curl_bufq_is_empty(const struct bufq *q) in Curl_bufq_is_empty() argument
310 return !q->head || chunk_is_empty(q->head); in Curl_bufq_is_empty()
313 bool Curl_bufq_is_full(const struct bufq *q) in Curl_bufq_is_full() argument
315 if(!q->tail || q->spare) in Curl_bufq_is_full()
317 if(q->chunk_count < q->max_chunks) in Curl_bufq_is_full()
319 if(q->chunk_count > q->max_chunks) in Curl_bufq_is_full()
322 return chunk_is_full(q->tail); in Curl_bufq_is_full()
325 static struct buf_chunk *get_spare(struct bufq *q) in get_spare() argument
329 if(q->spare) { in get_spare()
330 chunk = q->spare; in get_spare()
331 q->spare = chunk->next; in get_spare()
336 if(q->chunk_count >= q->max_chunks && (!(q->opts & BUFQ_OPT_SOFT_LIMIT))) in get_spare()
339 if(q->pool) { in get_spare()
340 if(bufcp_take(q->pool, &chunk)) in get_spare()
342 ++q->chunk_count; in get_spare()
346 chunk = calloc(1, sizeof(*chunk) + q->chunk_size); in get_spare()
349 chunk->dlen = q->chunk_size; in get_spare()
350 ++q->chunk_count; in get_spare()
355 static void prune_head(struct bufq *q) in prune_head() argument
359 while(q->head && chunk_is_empty(q->head)) { in prune_head()
360 chunk = q->head; in prune_head()
361 q->head = chunk->next; in prune_head()
362 if(q->tail == chunk) in prune_head()
363 q->tail = q->head; in prune_head()
364 if(q->pool) { in prune_head()
365 bufcp_put(q->pool, chunk); in prune_head()
366 --q->chunk_count; in prune_head()
368 else if((q->chunk_count > q->max_chunks) || in prune_head()
369 (q->opts & BUFQ_OPT_NO_SPARES)) { in prune_head()
374 --q->chunk_count; in prune_head()
377 chunk->next = q->spare; in prune_head()
378 q->spare = chunk; in prune_head()
396 static void prune_tail(struct bufq *q) in prune_tail() argument
400 while(q->tail && chunk_is_empty(q->tail)) { in prune_tail()
401 chunk = q->tail; in prune_tail()
402 q->tail = chunk_prev(q->head, chunk); in prune_tail()
403 if(q->tail) in prune_tail()
404 q->tail->next = NULL; in prune_tail()
405 if(q->head == chunk) in prune_tail()
406 q->head = q->tail; in prune_tail()
407 if(q->pool) { in prune_tail()
408 bufcp_put(q->pool, chunk); in prune_tail()
409 --q->chunk_count; in prune_tail()
411 else if((q->chunk_count > q->max_chunks) || in prune_tail()
412 (q->opts & BUFQ_OPT_NO_SPARES)) { in prune_tail()
417 --q->chunk_count; in prune_tail()
420 chunk->next = q->spare; in prune_tail()
421 q->spare = chunk; in prune_tail()
426 static struct buf_chunk *get_non_full_tail(struct bufq *q) in get_non_full_tail() argument
430 if(q->tail && !chunk_is_full(q->tail)) in get_non_full_tail()
431 return q->tail; in get_non_full_tail()
432 chunk = get_spare(q); in get_non_full_tail()
435 if(q->tail) { in get_non_full_tail()
436 q->tail->next = chunk; in get_non_full_tail()
437 q->tail = chunk; in get_non_full_tail()
440 DEBUGASSERT(!q->head); in get_non_full_tail()
441 q->head = q->tail = chunk; in get_non_full_tail()
447 ssize_t Curl_bufq_write(struct bufq *q, in Curl_bufq_write() argument
455 DEBUGASSERT(q->max_chunks > 0); in Curl_bufq_write()
457 tail = get_non_full_tail(q); in Curl_bufq_write()
459 if((q->chunk_count < q->max_chunks) || (q->opts & BUFQ_OPT_SOFT_LIMIT)) { in Curl_bufq_write()
480 CURLcode Curl_bufq_cwrite(struct bufq *q, in Curl_bufq_cwrite() argument
486 n = Curl_bufq_write(q, (const unsigned char *)buf, len, &result); in Curl_bufq_cwrite()
491 CURLcode Curl_bufq_unwrite(struct bufq *q, size_t len) in Curl_bufq_unwrite() argument
493 while(len && q->tail) { in Curl_bufq_unwrite()
494 len -= chunk_unwrite(q->tail, len); in Curl_bufq_unwrite()
495 prune_tail(q); in Curl_bufq_unwrite()
500 ssize_t Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, in Curl_bufq_read() argument
507 while(len && q->head) { in Curl_bufq_read()
508 n = chunk_read(q->head, buf, len); in Curl_bufq_read()
514 prune_head(q); in Curl_bufq_read()
523 CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len, in Curl_bufq_cread() argument
528 n = Curl_bufq_read(q, (unsigned char *)buf, len, &result); in Curl_bufq_cread()
533 bool Curl_bufq_peek(struct bufq *q, in Curl_bufq_peek() argument
536 if(q->head && chunk_is_empty(q->head)) { in Curl_bufq_peek()
537 prune_head(q); in Curl_bufq_peek()
539 if(q->head && !chunk_is_empty(q->head)) { in Curl_bufq_peek()
540 chunk_peek(q->head, pbuf, plen); in Curl_bufq_peek()
548 bool Curl_bufq_peek_at(struct bufq *q, size_t offset, in Curl_bufq_peek_at() argument
551 struct buf_chunk *c = q->head; in Curl_bufq_peek_at()
571 void Curl_bufq_skip(struct bufq *q, size_t amount) in Curl_bufq_skip() argument
575 while(amount && q->head) { in Curl_bufq_skip()
576 n = chunk_skip(q->head, amount); in Curl_bufq_skip()
578 prune_head(q); in Curl_bufq_skip()
582 ssize_t Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer, in Curl_bufq_pass() argument
589 while(Curl_bufq_peek(q, &buf, &blen)) { in Curl_bufq_pass()
608 Curl_bufq_skip(q, (size_t)chunk_written); in Curl_bufq_pass()
614 ssize_t Curl_bufq_write_pass(struct bufq *q, in Curl_bufq_write_pass() argument
623 if(Curl_bufq_is_full(q)) { in Curl_bufq_write_pass()
625 n = Curl_bufq_pass(q, writer, writer_ctx, err); in Curl_bufq_write_pass()
637 n = Curl_bufq_write(q, buf, len, err); in Curl_bufq_write_pass()
665 ssize_t Curl_bufq_sipn(struct bufq *q, size_t max_len, in Curl_bufq_sipn() argument
673 tail = get_non_full_tail(q); in Curl_bufq_sipn()
675 if(q->chunk_count < q->max_chunks) { in Curl_bufq_sipn()
704 static ssize_t bufq_slurpn(struct bufq *q, size_t max_len, in bufq_slurpn() argument
713 n = Curl_bufq_sipn(q, max_len, reader, reader_ctx, err); in bufq_slurpn()
736 if(q->tail && !chunk_is_full(q->tail)) in bufq_slurpn()
742 ssize_t Curl_bufq_slurp(struct bufq *q, Curl_bufq_reader *reader, in Curl_bufq_slurp() argument
745 return bufq_slurpn(q, 0, reader, reader_ctx, err); in Curl_bufq_slurp()