Coverage Report

Created: 2026-10-28 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/bufq.c
Line
Count
Source
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 ***************************************************************************/
24
#include "curl_setup.h"
25
26
#include "bufq.h"
27
28
static bool chunk_is_empty(const struct buf_chunk *chunk)
29
20.6M
{
30
20.6M
  return chunk->r_offset >= chunk->w_offset;
31
20.6M
}
32
33
static bool chunk_is_full(const struct buf_chunk *chunk)
34
10.9M
{
35
10.9M
  return chunk->w_offset >= chunk->dlen;
36
10.9M
}
37
38
static size_t chunk_len(const struct buf_chunk *chunk)
39
28.7M
{
40
28.7M
  return chunk->w_offset - chunk->r_offset;
41
28.7M
}
42
43
static void chunk_reset(struct buf_chunk *chunk)
44
3.98M
{
45
3.98M
  chunk->next = NULL;
46
3.98M
  chunk->r_offset = chunk->w_offset = 0;
47
3.98M
}
48
49
static size_t chunk_append(struct buf_chunk *chunk,
50
                           const uint8_t *buf, size_t len)
51
5.65M
{
52
5.65M
  uint8_t *p = &chunk->x.data[chunk->w_offset];
53
5.65M
  size_t n = chunk->dlen - chunk->w_offset;
54
5.65M
  DEBUGASSERT(chunk->dlen >= chunk->w_offset);
55
5.65M
  if(n) {
56
5.65M
    n = CURLMIN(n, len);
57
5.65M
    memcpy(p, buf, n);
58
5.65M
    chunk->w_offset += n;
59
5.65M
  }
60
5.65M
  return n;
61
5.65M
}
62
63
static size_t chunk_read(struct buf_chunk *chunk,
64
                         uint8_t *buf, size_t len)
65
727k
{
66
727k
  uint8_t *p = &chunk->x.data[chunk->r_offset];
67
727k
  size_t n = chunk->w_offset - chunk->r_offset;
68
727k
  DEBUGASSERT(chunk->w_offset >= chunk->r_offset);
69
727k
  if(!n) {
70
287
    return 0;
71
287
  }
72
726k
  else if(n <= len) {
73
647k
    memcpy(buf, p, n);
74
647k
    chunk->r_offset = chunk->w_offset = 0;
75
647k
    return n;
76
647k
  }
77
78.7k
  else {
78
78.7k
    memcpy(buf, p, len);
79
78.7k
    chunk->r_offset += len;
80
78.7k
    return len;
81
78.7k
  }
82
727k
}
83
84
static CURLcode chunk_slurpn(struct buf_chunk *chunk, size_t max_len,
85
                             Curl_bufq_reader *reader,
86
                             void *reader_ctx, size_t *pnread)
87
3.06M
{
88
3.06M
  uint8_t *p = &chunk->x.data[chunk->w_offset];
89
3.06M
  size_t n = chunk->dlen - chunk->w_offset; /* free amount */
90
3.06M
  CURLcode result;
91
92
3.06M
  *pnread = 0;
93
3.06M
  DEBUGASSERT(chunk->dlen >= chunk->w_offset);
94
3.06M
  if(!n)
95
0
    return CURLE_AGAIN;
96
3.06M
  if(max_len && n > max_len)
97
189k
    n = max_len;
98
3.06M
  result = reader(reader_ctx, p, n, pnread);
99
3.06M
  if(!result) {
100
1.98M
    DEBUGASSERT(*pnread <= n);
101
1.98M
    chunk->w_offset += *pnread;
102
1.98M
  }
103
3.06M
  return result;
104
3.06M
}
105
106
static void chunk_peek(const struct buf_chunk *chunk,
107
                       const uint8_t **pbuf, size_t *plen)
108
2.60M
{
109
2.60M
  DEBUGASSERT(chunk->w_offset >= chunk->r_offset);
110
2.60M
  *pbuf = &chunk->x.data[chunk->r_offset];
111
2.60M
  *plen = chunk->w_offset - chunk->r_offset;
112
2.60M
}
113
114
static void chunk_peek_at(const struct buf_chunk *chunk, size_t offset,
115
                          const uint8_t **pbuf, size_t *plen)
116
258k
{
117
258k
  offset += chunk->r_offset;
118
258k
  DEBUGASSERT(chunk->w_offset >= offset);
119
258k
  *pbuf = &chunk->x.data[offset];
120
258k
  *plen = chunk->w_offset - offset;
121
258k
}
122
123
static size_t chunk_skip(struct buf_chunk *chunk, size_t amount)
124
2.18M
{
125
2.18M
  size_t n = chunk->w_offset - chunk->r_offset;
126
2.18M
  DEBUGASSERT(chunk->w_offset >= chunk->r_offset);
127
2.18M
  if(n) {
128
2.18M
    n = CURLMIN(n, amount);
129
2.18M
    chunk->r_offset += n;
130
2.18M
    if(chunk->r_offset == chunk->w_offset)
131
1.75M
      chunk->r_offset = chunk->w_offset = 0;
132
2.18M
  }
133
2.18M
  return n;
134
2.18M
}
135
136
static void chunk_list_free(struct buf_chunk **anchor)
137
1.95M
{
138
1.95M
  struct buf_chunk *chunk;
139
2.23M
  while(*anchor) {
140
281k
    chunk = *anchor;
141
281k
    *anchor = chunk->next;
142
281k
    curlx_free(chunk);
143
281k
  }
144
1.95M
}
145
146
void Curl_bufcp_init(struct bufc_pool *pool,
147
                     size_t chunk_size, size_t spare_max)
148
81.6k
{
149
81.6k
  DEBUGASSERT(chunk_size > 0);
150
81.6k
  DEBUGASSERT(spare_max > 0);
151
81.6k
  memset(pool, 0, sizeof(*pool));
152
81.6k
  pool->chunk_size = chunk_size;
153
81.6k
  pool->spare_max = spare_max;
154
81.6k
}
155
156
static CURLcode bufcp_take(struct bufc_pool *pool,
157
                           struct buf_chunk **pchunk)
158
1.26M
{
159
1.26M
  struct buf_chunk *chunk = NULL;
160
161
1.26M
  if(pool->spare) {
162
950k
    chunk = pool->spare;
163
950k
    pool->spare = chunk->next;
164
950k
    --pool->spare_count;
165
950k
    chunk_reset(chunk);
166
950k
    *pchunk = chunk;
167
950k
    return CURLE_OK;
168
950k
  }
169
170
  /* Check for integer overflow before allocation */
171
313k
  if(pool->chunk_size > SIZE_MAX - sizeof(*chunk)) {
172
0
    *pchunk = NULL;
173
0
    return CURLE_OUT_OF_MEMORY;
174
0
  }
175
176
313k
  chunk = curlx_calloc(1, sizeof(*chunk) + pool->chunk_size);
177
313k
  if(!chunk) {
178
100
    *pchunk = NULL;
179
100
    return CURLE_OUT_OF_MEMORY;
180
100
  }
181
313k
  chunk->dlen = pool->chunk_size;
182
313k
  *pchunk = chunk;
183
313k
  return CURLE_OK;
184
313k
}
185
186
static void bufcp_put(struct bufc_pool *pool,
187
                      struct buf_chunk *chunk)
188
1.19M
{
189
1.19M
  if(pool->spare_count >= pool->spare_max) {
190
143k
    curlx_free(chunk);
191
143k
  }
192
1.04M
  else {
193
1.04M
    chunk_reset(chunk);
194
1.04M
    chunk->next = pool->spare;
195
1.04M
    pool->spare = chunk;
196
1.04M
    ++pool->spare_count;
197
1.04M
  }
198
1.19M
}
199
200
void Curl_bufcp_free(struct bufc_pool *pool)
201
81.6k
{
202
81.6k
  chunk_list_free(&pool->spare);
203
81.6k
  pool->spare_count = 0;
204
81.6k
}
205
206
static void bufq_init(struct bufq *q, struct bufc_pool *pool,
207
                      size_t chunk_size, size_t max_chunks, int opts)
208
935k
{
209
935k
  DEBUGASSERT(chunk_size > 0);
210
935k
  DEBUGASSERT(max_chunks > 0);
211
935k
  memset(q, 0, sizeof(*q));
212
935k
  q->chunk_size = chunk_size;
213
935k
  q->max_chunks = max_chunks;
214
935k
  q->pool = pool;
215
935k
  q->opts = opts;
216
935k
}
217
218
void Curl_bufq_init2(struct bufq *q, size_t chunk_size, size_t max_chunks,
219
                     int opts)
220
653k
{
221
653k
  bufq_init(q, NULL, chunk_size, max_chunks, opts);
222
653k
}
223
224
void Curl_bufq_init(struct bufq *q, size_t chunk_size, size_t max_chunks)
225
21.9k
{
226
21.9k
  bufq_init(q, NULL, chunk_size, max_chunks, BUFQ_OPT_NONE);
227
21.9k
}
228
229
void Curl_bufq_initp(struct bufq *q, struct bufc_pool *pool,
230
                     size_t max_chunks, int opts)
231
260k
{
232
260k
  bufq_init(q, pool, pool->chunk_size, max_chunks, opts);
233
260k
}
234
235
void Curl_bufq_free(struct bufq *q)
236
935k
{
237
935k
  chunk_list_free(&q->head);
238
935k
  chunk_list_free(&q->spare);
239
935k
  q->tail = NULL;
240
935k
  q->chunk_count = 0;
241
935k
}
242
243
void Curl_bufq_reset(struct bufq *q)
244
2.73M
{
245
2.73M
  struct buf_chunk *chunk;
246
3.53M
  while(q->head) {
247
797k
    chunk = q->head;
248
797k
    q->head = chunk->next;
249
797k
    chunk->next = q->spare;
250
797k
    q->spare = chunk;
251
797k
  }
252
2.73M
  q->tail = NULL;
253
2.73M
}
254
255
size_t Curl_bufq_len(const struct bufq *q)
256
14.2M
{
257
14.2M
  const struct buf_chunk *chunk = q->head;
258
14.2M
  size_t len = 0;
259
41.7M
  while(chunk) {
260
27.5M
    len += chunk_len(chunk);
261
27.5M
    chunk = chunk->next;
262
27.5M
  }
263
14.2M
  return len;
264
14.2M
}
265
266
bool Curl_bufq_is_empty(const struct bufq *q)
267
29.2M
{
268
29.2M
  return !q->head || chunk_is_empty(q->head);
269
29.2M
}
270
271
bool Curl_bufq_is_full(const struct bufq *q)
272
1.40M
{
273
1.40M
  if(!q->tail || q->spare)
274
558k
    return FALSE;
275
845k
  if(q->chunk_count < q->max_chunks)
276
154k
    return FALSE;
277
691k
  if(q->chunk_count > q->max_chunks)
278
4.95k
    return TRUE;
279
  /* we have no spares and cannot make more, is the tail full? */
280
686k
  return chunk_is_full(q->tail);
281
691k
}
282
283
static struct buf_chunk *get_spare(struct bufq *q)
284
5.69M
{
285
5.69M
  struct buf_chunk *chunk = NULL;
286
287
5.69M
  if(q->spare) {
288
1.98M
    chunk = q->spare;
289
1.98M
    q->spare = chunk->next;
290
1.98M
    chunk_reset(chunk);
291
1.98M
    return chunk;
292
1.98M
  }
293
294
3.70M
  if(q->chunk_count >= q->max_chunks && (!(q->opts & BUFQ_OPT_SOFT_LIMIT)))
295
2.30M
    return NULL;
296
297
1.40M
  if(q->pool) {
298
1.26M
    if(bufcp_take(q->pool, &chunk))
299
100
      return NULL;
300
1.26M
    ++q->chunk_count;
301
1.26M
    return chunk;
302
1.26M
  }
303
142k
  else {
304
    /* Check for integer overflow before allocation */
305
142k
    if(q->chunk_size > SIZE_MAX - sizeof(*chunk)) {
306
0
      return NULL;
307
0
    }
308
309
142k
    chunk = curlx_calloc(1, sizeof(*chunk) + q->chunk_size);
310
142k
    if(!chunk)
311
247
      return NULL;
312
142k
    chunk->dlen = q->chunk_size;
313
142k
    ++q->chunk_count;
314
142k
    return chunk;
315
142k
  }
316
1.40M
}
317
318
static void prune_head(struct bufq *q)
319
3.00M
{
320
3.00M
  struct buf_chunk *chunk;
321
322
5.49M
  while(q->head && chunk_is_empty(q->head)) {
323
2.49M
    chunk = q->head;
324
2.49M
    q->head = chunk->next;
325
2.49M
    if(q->tail == chunk)
326
1.45M
      q->tail = q->head;
327
2.49M
    if(q->pool) {
328
1.19M
      bufcp_put(q->pool, chunk);
329
1.19M
      --q->chunk_count;
330
1.19M
    }
331
1.30M
    else if((q->chunk_count > q->max_chunks) ||
332
1.27M
            (q->opts & BUFQ_OPT_NO_SPARES)) {
333
      /* SOFT_LIMIT allowed us more than max. free spares until
334
       * we are at max again. Or free them if we are configured
335
       * to not use spares. */
336
29.5k
      curlx_free(chunk);
337
29.5k
      --q->chunk_count;
338
29.5k
    }
339
1.27M
    else {
340
1.27M
      chunk->next = q->spare;
341
1.27M
      q->spare = chunk;
342
1.27M
    }
343
2.49M
  }
344
3.00M
}
345
346
static struct buf_chunk *get_non_full_tail(struct bufq *q)
347
11.0M
{
348
11.0M
  struct buf_chunk *chunk;
349
350
11.0M
  if(q->tail && !chunk_is_full(q->tail))
351
5.32M
    return q->tail;
352
5.69M
  chunk = get_spare(q);
353
5.69M
  if(chunk) {
354
    /* new tail, and possibly new head */
355
3.38M
    if(q->tail) {
356
1.57M
      q->tail->next = chunk;
357
1.57M
      q->tail = chunk;
358
1.57M
    }
359
1.81M
    else {
360
1.81M
      DEBUGASSERT(!q->head);
361
1.81M
      q->head = q->tail = chunk;
362
1.81M
    }
363
3.38M
  }
364
5.69M
  return chunk;
365
5.69M
}
366
367
CURLcode Curl_bufq_write(struct bufq *q,
368
                         const uint8_t *buf, size_t len,
369
                         size_t *pnwritten)
370
13.8M
{
371
13.8M
  struct buf_chunk *tail;
372
13.8M
  size_t n;
373
374
13.8M
  DEBUGASSERT(q->max_chunks > 0);
375
13.8M
  *pnwritten = 0;
376
19.5M
  while(len) {
377
6.88M
    tail = get_non_full_tail(q);
378
6.88M
    if(!tail) {
379
1.23M
      if((q->chunk_count < q->max_chunks) || (q->opts & BUFQ_OPT_SOFT_LIMIT))
380
        /* should have gotten a tail, but did not */
381
301
        return CURLE_OUT_OF_MEMORY;
382
1.23M
      break;
383
1.23M
    }
384
5.65M
    n = chunk_append(tail, buf, len);
385
5.65M
    if(!n)
386
0
      break;
387
5.65M
    *pnwritten += n;
388
5.65M
    buf += n;
389
5.65M
    len -= n;
390
5.65M
  }
391
13.8M
  return (!*pnwritten && len) ? CURLE_AGAIN : CURLE_OK;
392
13.8M
}
393
394
CURLcode Curl_bufq_cwrite(struct bufq *q,
395
                          const char *buf, size_t len,
396
                          size_t *pnwritten)
397
6.22M
{
398
6.22M
  return Curl_bufq_write(q, (const uint8_t *)buf, len, pnwritten);
399
6.22M
}
400
401
CURLcode Curl_bufq_read(struct bufq *q, uint8_t *buf, size_t len,
402
                        size_t *pnread)
403
735k
{
404
735k
  *pnread = 0;
405
1.46M
  while(len && q->head) {
406
727k
    size_t n = chunk_read(q->head, buf, len);
407
727k
    if(n) {
408
726k
      *pnread += n;
409
726k
      buf += n;
410
726k
      len -= n;
411
726k
    }
412
727k
    prune_head(q);
413
727k
  }
414
735k
  return (!*pnread) ? CURLE_AGAIN : CURLE_OK;
415
735k
}
416
417
CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len,
418
                         size_t *pnread)
419
112k
{
420
112k
  return Curl_bufq_read(q, (uint8_t *)buf, len, pnread);
421
112k
}
422
423
bool Curl_bufq_peek(struct bufq *q,
424
                    const uint8_t **pbuf, size_t *plen)
425
4.37M
{
426
4.37M
  if(q->head && chunk_is_empty(q->head)) {
427
90.2k
    prune_head(q);
428
90.2k
  }
429
4.37M
  if(q->head && !chunk_is_empty(q->head)) {
430
2.60M
    chunk_peek(q->head, pbuf, plen);
431
2.60M
    return TRUE;
432
2.60M
  }
433
1.76M
  *pbuf = NULL;
434
1.76M
  *plen = 0;
435
1.76M
  return FALSE;
436
4.37M
}
437
438
bool Curl_bufq_peek_at(struct bufq *q, size_t offset,
439
                       const uint8_t **pbuf, size_t *plen)
440
852k
{
441
852k
  struct buf_chunk *c = q->head;
442
852k
  size_t clen;
443
444
1.77M
  while(c) {
445
1.18M
    clen = chunk_len(c);
446
1.18M
    if(!clen)
447
1.86k
      break;
448
1.17M
    if(offset >= clen) {
449
921k
      offset -= clen;
450
921k
      c = c->next;
451
921k
      continue;
452
921k
    }
453
258k
    chunk_peek_at(c, offset, pbuf, plen);
454
258k
    return TRUE;
455
1.17M
  }
456
593k
  *pbuf = NULL;
457
593k
  *plen = 0;
458
593k
  return FALSE;
459
852k
}
460
461
void Curl_bufq_skip(struct bufq *q, size_t amount)
462
2.58M
{
463
2.58M
  size_t n;
464
465
4.76M
  while(amount && q->head) {
466
2.18M
    n = chunk_skip(q->head, amount);
467
2.18M
    amount -= n;
468
2.18M
    prune_head(q);
469
2.18M
  }
470
2.58M
}
471
472
CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer,
473
                        void *writer_ctx, size_t *pwritten)
474
810k
{
475
810k
  const uint8_t *buf;
476
810k
  size_t blen;
477
810k
  CURLcode result = CURLE_OK;
478
479
810k
  *pwritten = 0;
480
1.64M
  while(Curl_bufq_peek(q, &buf, &blen)) {
481
911k
    size_t chunk_written;
482
483
911k
    result = writer(writer_ctx, buf, blen, &chunk_written);
484
911k
    if(result) {
485
80.6k
      if((result == CURLE_AGAIN) && *pwritten) {
486
        /* blocked on subsequent write, report success */
487
60.9k
        result = CURLE_OK;
488
60.9k
      }
489
80.6k
      break;
490
80.6k
    }
491
831k
    if(!chunk_written) {
492
0
      if(!*pwritten) {
493
        /* treat as blocked */
494
0
        result = CURLE_AGAIN;
495
0
      }
496
0
      break;
497
0
    }
498
831k
    *pwritten += chunk_written;
499
831k
    Curl_bufq_skip(q, chunk_written);
500
831k
  }
501
810k
  return result;
502
810k
}
503
504
CURLcode Curl_bufq_write_pass(struct bufq *q,
505
                              const uint8_t *buf, size_t len,
506
                              Curl_bufq_writer *writer, void *writer_ctx,
507
                              size_t *pwritten)
508
573k
{
509
573k
  CURLcode result = CURLE_OK;
510
573k
  size_t n;
511
512
573k
  *pwritten = 0;
513
1.15M
  while(len) {
514
592k
    if(Curl_bufq_is_full(q)) {
515
      /* try to make room in case we are full */
516
26.5k
      result = Curl_bufq_pass(q, writer, writer_ctx, &n);
517
26.5k
      if(result) {
518
6.80k
        if(result != CURLE_AGAIN) {
519
          /* real error, fail */
520
0
          return result;
521
0
        }
522
        /* would block, bufq is full, give up */
523
6.80k
        break;
524
6.80k
      }
525
26.5k
    }
526
527
    /* Add to bufq as much as there is room for */
528
585k
    result = Curl_bufq_write(q, buf, len, &n);
529
585k
    if(result) {
530
1.35k
      if(result != CURLE_AGAIN)
531
        /* real error, fail */
532
45
        return result;
533
      /* result == CURLE_AGAIN */
534
1.30k
      if(*pwritten)
535
        /* we did write successfully before */
536
459
        result = CURLE_OK;
537
1.30k
      return result;
538
1.35k
    }
539
583k
    else if(n == 0)
540
      /* edge case of writer returning 0 (and len is >0)
541
       * break or we might enter an infinite loop here */
542
0
      break;
543
544
    /* Track what we added to bufq */
545
583k
    buf += n;
546
583k
    len -= n;
547
583k
    *pwritten += n;
548
583k
  }
549
550
571k
  return (!*pwritten && len) ? CURLE_AGAIN : CURLE_OK;
551
573k
}
552
553
CURLcode Curl_bufq_sipn(struct bufq *q, size_t max_len,
554
                        Curl_bufq_reader *reader, void *reader_ctx,
555
                        size_t *pnread)
556
4.12M
{
557
4.12M
  struct buf_chunk *tail = NULL;
558
559
4.12M
  *pnread = 0;
560
4.12M
  tail = get_non_full_tail(q);
561
4.12M
  if(!tail) {
562
1.06M
    if(q->chunk_count < q->max_chunks)
563
46
      return CURLE_OUT_OF_MEMORY;
564
    /* full, blocked */
565
1.06M
    return CURLE_AGAIN;
566
1.06M
  }
567
568
3.06M
  return chunk_slurpn(tail, max_len, reader, reader_ctx, pnread);
569
4.12M
}
570
571
/**
572
 * Read up to `max_len` bytes and append it to the end of the buffer queue.
573
 * if `max_len` is 0, no limit is imposed and the call behaves exactly
574
 * the same as `Curl_bufq_slurp()`.
575
 * Returns the total amount of buf read (may be 0) in `pnread` or error
576
 * Note that even in case of an error chunks may have been read and
577
 * the buffer queue will have different length than before.
578
 */
579
static CURLcode bufq_slurpn(struct bufq *q, size_t max_len,
580
                            Curl_bufq_reader *reader, void *reader_ctx,
581
                            size_t *pnread)
582
699k
{
583
699k
  CURLcode result;
584
585
699k
  *pnread = 0;
586
1.67M
  while(1) {
587
1.67M
    size_t n;
588
1.67M
    result = Curl_bufq_sipn(q, max_len, reader, reader_ctx, &n);
589
1.67M
    if(result) {
590
623k
      if(!*pnread || result != CURLE_AGAIN) {
591
        /* blocked on first read or real error, fail */
592
515k
        return result;
593
515k
      }
594
107k
      result = CURLE_OK;
595
107k
      break;
596
623k
    }
597
1.04M
    else if(n == 0) {
598
      /* eof, result remains CURLE_OK */
599
0
      break;
600
0
    }
601
1.04M
    *pnread += n;
602
1.04M
    if(max_len) {
603
0
      DEBUGASSERT(n <= max_len);
604
0
      max_len -= n;
605
0
      if(!max_len)
606
0
        break;
607
0
    }
608
    /* give up slurping when we get less bytes than we asked for */
609
1.04M
    if(q->tail && !chunk_is_full(q->tail))
610
76.1k
      break;
611
1.04M
  }
612
183k
  return result;
613
699k
}
614
615
CURLcode Curl_bufq_slurp(struct bufq *q, Curl_bufq_reader *reader,
616
                         void *reader_ctx, size_t *pnread)
617
699k
{
618
699k
  return bufq_slurpn(q, 0, reader, reader_ctx, pnread);
619
699k
}