Coverage Report

Created: 2026-07-25 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/third_party/ngtcp2/lib/ngtcp2_buf.h
Line
Count
Source
1
/*
2
 * ngtcp2
3
 *
4
 * Copyright (c) 2017 ngtcp2 contributors
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining
7
 * a copy of this software and associated documentation files (the
8
 * "Software"), to deal in the Software without restriction, including
9
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * distribute, sublicense, and/or sell copies of the Software, and to
11
 * permit persons to whom the Software is furnished to do so, subject to
12
 * the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be
15
 * included in all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 */
25
#ifndef NGTCP2_BUF_H
26
#define NGTCP2_BUF_H
27
28
#ifdef HAVE_CONFIG_H
29
#  include <config.h>
30
#endif /* defined(HAVE_CONFIG_H) */
31
32
#include <ngtcp2/ngtcp2.h>
33
34
typedef struct ngtcp2_buf {
35
  /* begin points to the beginning of the buffer. */
36
  uint8_t *begin;
37
  /* end points to the one beyond of the last byte of the buffer */
38
  uint8_t *end;
39
  /* pos points to the start of data.  Typically, this points to the
40
     point that next data should be read.  Initially, it points to
41
     |begin|. */
42
  uint8_t *pos;
43
  /* last points to the one beyond of the last data of the buffer.
44
     Typically, new data is written at this point.  Initially, it
45
     points to |begin|. */
46
  uint8_t *last;
47
} ngtcp2_buf;
48
49
/*
50
 * ngtcp2_buf_init initializes |buf| with the given buffer.
51
 */
52
void ngtcp2_buf_init(ngtcp2_buf *buf, uint8_t *begin, size_t len);
53
54
/*
55
 * ngtcp2_buf_reset resets pos and last fields to match begin field to
56
 * make ngtcp2_buf_len(buf) return 0.
57
 */
58
void ngtcp2_buf_reset(ngtcp2_buf *buf);
59
60
/*
61
 * ngtcp2_buf_left returns the number of additional bytes which can be
62
 * written to the underlying buffer.  In other words, it returns
63
 * buf->end - buf->last.
64
 */
65
0
static inline size_t ngtcp2_buf_left(const ngtcp2_buf *buf) {
66
0
  return (size_t)(buf->end - buf->last);
67
0
}
Unexecuted instantiation: ngtcp2_acktr.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_balloc.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_buf.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_conn.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_frame_chain.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_gaptr.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_idtr.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_ksl.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_objalloc.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_pkt.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_ppe.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_qlog.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_rob.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_rst.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_rtb.c:ngtcp2_buf_left
Unexecuted instantiation: ngtcp2_strm.c:ngtcp2_buf_left
68
69
/*
70
 * ngtcp2_buf_len returns the number of bytes left to read.  In other
71
 * words, it returns buf->last - buf->pos.
72
 */
73
0
#define ngtcp2_buf_len(BUF) (size_t)((BUF)->last - (BUF)->pos)
74
75
/*
76
 * ngtcp2_buf_cap returns the capacity of the buffer.  In other words,
77
 * it returns buf->end - buf->begin.
78
 */
79
size_t ngtcp2_buf_cap(const ngtcp2_buf *buf);
80
81
/*
82
 * ngtcp2_buf_trunc truncates the number of bytes to read to at most
83
 * |len|.  In other words, it sets buf->last = buf->pos + len if
84
 * ngtcp2_buf_len(buf) > len.
85
 */
86
void ngtcp2_buf_trunc(ngtcp2_buf *buf, size_t len);
87
88
/*
89
 * ngtcp2_buf_chain is a linked list of ngtcp2_buf.
90
 */
91
typedef struct ngtcp2_buf_chain ngtcp2_buf_chain;
92
93
struct ngtcp2_buf_chain {
94
  ngtcp2_buf_chain *next;
95
  ngtcp2_buf buf;
96
};
97
98
/*
99
 * ngtcp2_buf_chain_new creates new ngtcp2_buf_chain and initializes
100
 * the internal buffer with |len| bytes space.
101
 *
102
 * This function returns 0 if it succeeds, or one of the following
103
 * negative error codes:
104
 *
105
 * NGTCP2_ERR_NOMEM
106
 *     Out of memory
107
 */
108
int ngtcp2_buf_chain_new(ngtcp2_buf_chain **pbufchain, size_t len,
109
                         const ngtcp2_mem *mem);
110
111
/*
112
 * ngtcp2_buf_chain_del deletes the resource allocated by |bufchain|.
113
 * It also deletes the memory pointed by |bufchain|.
114
 */
115
void ngtcp2_buf_chain_del(ngtcp2_buf_chain *bufchain, const ngtcp2_mem *mem);
116
117
#endif /* !defined(NGTCP2_BUF_H) */