Artifactspublic-v0

curl

master
ply4 git calls37 ms290 KiB3 cachedprotocol v2
257 lines9.6 KiBRaw
1#ifndef HEADER_CURL_BUFQ_H
2#define HEADER_CURL_BUFQ_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26#include "curl_setup.h"
28/**
29 * A chunk of bytes for reading and writing.
30 * The size is fixed a creation with read and write offset
31 * for where unread content is.
32 */
33struct buf_chunk {
34 struct buf_chunk *next; /* to keep it in a list */
35 size_t dlen; /* the amount of allocated x.data[] */
36 size_t r_offset; /* first unread bytes */
37 size_t w_offset; /* one after last written byte */
38 union {
39 uint8_t data[1]; /* the buffer for `dlen` bytes */
40 void *dummy; /* alignment */
41 } x;
42};
44/**
45 * A pool for providing/keeping a number of chunks of the same size
46 *
47 * The same pool can be shared by many `bufq` instances. A pool is not thread
48 * safe. All bufqs using it are supposed to operate in the same thread.
49 */
50struct bufc_pool {
51 struct buf_chunk *spare; /* list of available spare chunks */
52 size_t chunk_size; /* the size of chunks in this pool */
53 size_t spare_count; /* current number of spare chunks in list */
54 size_t spare_max; /* max number of spares to keep */
55};
57void Curl_bufcp_init(struct bufc_pool *pool,
58 size_t chunk_size, size_t spare_max);
60void Curl_bufcp_free(struct bufc_pool *pool);
62/**
63 * A queue of byte chunks for reading and writing.
64 * Reading is done from `head`, writing is done to `tail`.
65 *
66 * `bufq`s can be empty or full or neither. Its `len` is the number
67 * of bytes that can be read. For an empty bufq, `len` will be 0.
68 *
69 * By default, a bufq can hold up to `max_chunks * chunk_size` number
70 * of bytes. When `max_chunks` are used (in the `head` list) and the
71 * `tail` chunk is full, the bufq will report that it is full.
72 *
73 * On a full bufq, `len` may be less than the maximum number of bytes,
74 * e.g. when the head chunk is partially read. `len` may also become
75 * larger than the max when option `BUFQ_OPT_SOFT_LIMIT` is used.
76 *
77 * By default, writing to a full bufq will return (-1, CURLE_AGAIN). Same
78 * as reading from an empty bufq.
79 * With `BUFQ_OPT_SOFT_LIMIT` set, a bufq will allow writing beyond this limit
80 * and use more than `max_chunks`. It will report that it is full
81 * nevertheless. This is provided for situation where writes preferably never
82 * fail (except for memory exhaustion).
83 *
84 * By default and without a pool, a bufq will keep chunks that read
85 * empty in its `spare` list. Option `BUFQ_OPT_NO_SPARES` will
86 * disable that and free chunks once they become empty.
87 *
88 * When providing a pool to a bufq, all chunk creation and spare handling
89 * will be delegated to that pool.
90 */
91struct bufq {
92 struct buf_chunk *head; /* chunk with bytes to read from */
93 struct buf_chunk *tail; /* chunk to write to */
94 struct buf_chunk *spare; /* list of free chunks, unless `pool` */
95 struct bufc_pool *pool; /* optional pool for free chunks */
96 size_t chunk_count; /* current number of chunks in `head+spare` */
97 size_t max_chunks; /* max `head` chunks to use */
98 size_t chunk_size; /* size of chunks to manage */
99 int opts; /* options for handling queue, see below */
100};
102/**
103 * Default behaviour: chunk limit is "hard", meaning attempts to write
104 * more bytes than can be hold in `max_chunks` is refused and will return
105 * -1, CURLE_AGAIN. */
106#define BUFQ_OPT_NONE 0
107/**
108 * Make `max_chunks` a "soft" limit. A bufq will report that it is "full"
109 * when `max_chunks` are used, but allows writing beyond this limit.
110 */
111#define BUFQ_OPT_SOFT_LIMIT (1 << 0)
112/**
113 * Do not keep spare chunks.
114 */
115#define BUFQ_OPT_NO_SPARES (1 << 1)
117/**
118 * Initialize a buffer queue that can hold up to `max_chunks` buffers
119 * each of size `chunk_size`. The bufq will not allow writing of
120 * more bytes than can be held in `max_chunks`.
121 */
122void Curl_bufq_init(struct bufq *q, size_t chunk_size, size_t max_chunks);
124/**
125 * Initialize a buffer queue that can hold up to `max_chunks` buffers
126 * each of size `chunk_size` with the given options. See `BUFQ_OPT_*`.
127 */
128void Curl_bufq_init2(struct bufq *q, size_t chunk_size,
129 size_t max_chunks, int opts);
131void Curl_bufq_initp(struct bufq *q, struct bufc_pool *pool,
132 size_t max_chunks, int opts);
134/**
135 * Reset the buffer queue to be empty. Keep any allocated buffer chunks
136 * around.
137 */
138void Curl_bufq_reset(struct bufq *q);
140/**
141 * Free all resources held by the buffer queue.
142 */
143void Curl_bufq_free(struct bufq *q);
145/**
146 * Return the total amount of data in the queue.
147 */
148size_t Curl_bufq_len(const struct bufq *q);
150/**
151 * Returns TRUE iff there is no data in the buffer queue.
152 */
153bool Curl_bufq_is_empty(const struct bufq *q);
155/**
156 * Returns TRUE iff there is no space left in the buffer queue.
157 */
158bool Curl_bufq_is_full(const struct bufq *q);
160/**
161 * Write buf to the end of the buffer queue. The buf is copied
162 * and the amount of copied bytes is returned.
163 * CURLE_AGAIN is returned if the buffer queue is full.
164 */
165CURLcode Curl_bufq_write(struct bufq *q,
166 const uint8_t *buf, size_t len,
167 size_t *pnwritten);
169CURLcode Curl_bufq_cwrite(struct bufq *q,
170 const char *buf, size_t len,
171 size_t *pnwritten);
173/**
174 * Read buf from the start of the buffer queue. The buf is copied
175 * and the amount of copied bytes is returned.
176 */
177CURLcode Curl_bufq_read(struct bufq *q, uint8_t *buf, size_t len,
178 size_t *pnread);
180CURLcode Curl_bufq_cread(struct bufq *q, char *buf, size_t len,
181 size_t *pnread);
183/**
184 * Peek at the head chunk in the buffer queue. Returns a pointer to
185 * the chunk buf (at the current offset) and its length. Does not
186 * modify the buffer queue.
187 * Returns TRUE iff bytes are available. Sets `pbuf` to NULL and `plen`
188 * to 0 when no bytes are available.
189 * Repeated calls return the same information until the buffer queue
190 * is modified, see `Curl_bufq_skip()``
191 */
192bool Curl_bufq_peek(struct bufq *q,
193 const uint8_t **pbuf, size_t *plen);
195bool Curl_bufq_peek_at(struct bufq *q, size_t offset,
196 const uint8_t **pbuf, size_t *plen);
198/**
199 * Tell the buffer queue to discard `amount` buf bytes at the head of the
200 * queue. Skipping more buf than is currently buffered will empty the queue.
201 */
202void Curl_bufq_skip(struct bufq *q, size_t amount);
204typedef CURLcode Curl_bufq_writer(void *writer_ctx,
205 const uint8_t *buf, size_t len,
206 size_t *pwritten);
208/**
209 * Passes the chunks in the buffer queue to the writer and returns
210 * the amount of buf written. A writer may return -1 and CURLE_AGAIN
211 * to indicate blocking at which point the queue will stop and return
212 * the amount of buf passed so far.
213 * -1 is returned on any other errors reported by the writer.
214 * Note that in case of a -1 chunks may have been written and
215 * the buffer queue will have different length than before.
216 */
217CURLcode Curl_bufq_pass(struct bufq *q, Curl_bufq_writer *writer,
218 void *writer_ctx, size_t *pwritten);
220typedef CURLcode Curl_bufq_reader(void *reader_ctx,
221 uint8_t *buf, size_t len,
222 size_t *pnread);
224/**
225 * Read bytes and append them to the end of the buffer queue until the
226 * reader returns blocking or the queue is full. A reader returns
227 * CURLE_AGAIN to indicate blocking.
228 * Returns the total amount of buf read (may be 0) in `pnread` on success.
229 * Note that in case of an error chunks may have been read and
230 * the buffer queue will have different length than before.
231 */
232CURLcode Curl_bufq_slurp(struct bufq *q, Curl_bufq_reader *reader,
233 void *reader_ctx, size_t *pnread);
235/**
236 * Read *once* up to `max_len` bytes and append it to the buffer.
237 * if `max_len` is 0, no limit is imposed besides the chunk space.
238 * Returns the total amount of buf read (may be 0) or -1 on other
239 * reader errors.
240 */
241CURLcode Curl_bufq_sipn(struct bufq *q, size_t max_len,
242 Curl_bufq_reader *reader, void *reader_ctx,
243 size_t *pnread);
245/**
246 * Write buf to the end of the buffer queue.
247 * Write bufq content or passed `buf` directly using the `writer`
248 * callback when it sees fit. 'buf' might get passed directly
249 * on or is placed into the buffer, depending on `len` and current
250 * amount buffered, chunk size, etc.
251 */
252CURLcode Curl_bufq_write_pass(struct bufq *q,
253 const uint8_t *buf, size_t len,
254 Curl_bufq_writer *writer, void *writer_ctx,
255 size_t *pwritten);
257#endif /* HEADER_CURL_BUFQ_H */
Diagnostics4 git calls · 37 ms
CallStatusSizeTime037 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=32
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2003.2 KiB · hit32 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3307
git.response.cache=HIT
git.response.duration_ms=32
git.fetch.wants=c53749d84e3653dd0cb500d6b97c775a5d3e2df8
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3307
git.pkt.payload.max=3286
git.sideband.band1.bytes=3285
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e1725c9f016102
Request
0008ef27…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format