Artifactspublic-v0

curl

master
ply4 git calls316 ms290 KiB2 cachedprotocol v2
358 lines9.6 KiBRaw
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 "first.h"
26struct t582_Sockets {
27 curl_socket_t *sockets;
28 int count; /* number of sockets actually stored in array */
29 int max_count; /* max number of sockets that fit in allocated array */
30};
32struct t582_ReadWriteSockets {
33 struct t582_Sockets read, write;
34};
36/**
37 * Remove a file descriptor from a sockets array.
38 */
39static void t582_removeFd(struct t582_Sockets *sockets, curl_socket_t fd,
40 int mention)
42 int i;
44 if(mention)
45 curl_mfprintf(stderr, "Remove socket fd %" FMT_SOCKET_T "\n", fd);
47 for(i = 0; i < sockets->count; ++i) {
48 if(sockets->sockets[i] == fd) {
49 if(i < sockets->count - 1)
50 memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
51 sizeof(curl_socket_t) * (sockets->count - (i + 1)));
52 --sockets->count;
53 }
54 }
57/**
58 * Add a file descriptor to a sockets array.
59 */
60static void t582_addFd(struct t582_Sockets *sockets, curl_socket_t fd,
61 const char *what)
63 /**
64 * To ensure we only have each file descriptor once, we remove it then add
65 * it again.
66 */
67 curl_mfprintf(stderr, "Add socket fd %" FMT_SOCKET_T " for %s\n", fd, what);
68 t582_removeFd(sockets, fd, 0);
69 /*
70 * Allocate array storage when required.
71 */
72 if(!sockets->sockets) {
73 sockets->sockets = curlx_malloc(sizeof(curl_socket_t) * 20U);
74 if(!sockets->sockets)
75 return;
76 sockets->max_count = 20;
77 }
78 else if(sockets->count >= sockets->max_count) {
79 /* this cannot happen in normal cases */
80 curl_mfprintf(stderr, "too many file handles error\n");
81 exit(2);
82 }
83 /*
84 * Add file descriptor to array.
85 */
86 sockets->sockets[sockets->count] = fd;
87 ++sockets->count;
90/**
91 * Callback invoked by curl to poll reading / writing of a socket.
92 */
93static int t582_curlSocketCallback(CURL *curl, curl_socket_t s, int action,
94 void *userp, void *socketp)
96 struct t582_ReadWriteSockets *sockets = userp;
98 (void)curl;
99 (void)socketp;
101 if(action == CURL_POLL_IN || action == CURL_POLL_INOUT)
102 t582_addFd(&sockets->read, s, "read");
104 if(action == CURL_POLL_OUT || action == CURL_POLL_INOUT)
105 t582_addFd(&sockets->write, s, "write");
107 if(action == CURL_POLL_REMOVE) {
108 t582_removeFd(&sockets->read, s, 1);
109 t582_removeFd(&sockets->write, s, 0);
110 }
112 return 0;
115/**
116 * Callback invoked by curl to set a timeout.
117 */
118static int t582_curlTimerCallback(CURLM *multi, long timeout_ms, void *userp)
120 struct curltime *timeout = userp;
122 (void)multi;
123 if(timeout_ms != -1) {
124 *timeout = curlx_now();
125 timeout->tv_usec += (int)timeout_ms * 1000;
126 }
127 else {
128 timeout->tv_sec = -1;
129 }
130 return 0;
133/**
134 * Check for curl completion.
135 */
136static int t582_checkForCompletion(CURLM *multi, int *success)
138 int result = 0;
139 *success = 0;
140 while(1) {
141 int numMessages;
142 CURLMsg *message = curl_multi_info_read(multi, &numMessages);
143 if(!message)
144 break;
145 if(message->msg == CURLMSG_DONE) {
146 result = 1;
147 if(message->data.result == CURLE_OK)
148 *success = 1;
149 else
150 *success = 0;
151 }
152 else {
153 curl_mfprintf(stderr, "Got an unexpected message from curl: %d\n",
154 (int)message->msg);
155 result = 1;
156 *success = 0;
157 }
158 }
159 return result;
162static ssize_t t582_getMicroSecondTimeout(struct curltime *timeout)
164 struct curltime now;
165 ssize_t result;
166 now = curlx_now();
167 result = (ssize_t)(((timeout->tv_sec - now.tv_sec) * 1000000) +
168 timeout->tv_usec - now.tv_usec);
169 if(result < 0)
170 result = 0;
172 return result;
175/**
176 * Update a fd_set with all of the sockets in use.
177 */
178static void t582_updateFdSet(struct t582_Sockets *sockets, fd_set *fdset,
179 curl_socket_t *maxFd)
181 int i;
182 for(i = 0; i < sockets->count; ++i) {
183 FD_SET(sockets->sockets[i], fdset);
184 if(*maxFd < sockets->sockets[i] + 1) {
185 *maxFd = sockets->sockets[i] + 1;
186 }
187 }
190static void notifyCurl(CURLM *multi, curl_socket_t s, int evBitmask,
191 const char *info)
193 int numhandles = 0;
194 CURLMcode mresult = curl_multi_socket_action(multi, s, evBitmask,
195 &numhandles);
196 if(mresult != CURLM_OK) {
197 curl_mfprintf(stderr, "curl error on %s (%d) %s\n",
198 info, mresult, curl_multi_strerror(mresult));
199 }
202/**
203 * Invoke curl when a file descriptor is set.
204 */
205static void t582_checkFdSet(CURLM *multi, struct t582_Sockets *sockets,
206 fd_set *fdset, int evBitmask, const char *name)
208 int i;
209 for(i = 0; i < sockets->count; ++i) {
210 if(FD_ISSET(sockets->sockets[i], fdset)) {
211 notifyCurl(multi, sockets->sockets[i], evBitmask, name);
212 }
213 }
216static CURLcode test_lib582(const char *URL)
218 CURLcode result = CURLE_OK;
219 CURL *curl = NULL;
220 char errbuf[STRERROR_LEN];
221 FILE *hd_src = NULL;
222 int hd;
223 curlx_struct_stat file_info;
224 CURLM *multi = NULL;
225 struct t582_ReadWriteSockets sockets = { { NULL, 0, 0 }, { NULL, 0, 0 } };
226 int success = 0;
227 struct curltime timeout = { 0 };
228 timeout.tv_sec = (time_t)-1;
230 if(test_argc < 5)
231 return TEST_ERR_MAJOR_BAD;
233 start_test_timing();
235 if(!libtest_arg3) {
236 curl_mfprintf(stderr, "Usage: lib582 [url] [filename] [username]\n");
237 return TEST_ERR_USAGE;
238 }
240 hd_src = curlx_fopen(libtest_arg2, "rb");
241 if(!hd_src) {
242 curl_mfprintf(stderr, "fopen() failed with error (%d) %s\n",
243 errno, curlx_strerror(errno, errbuf, sizeof(errbuf)));
244 curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
245 return TEST_ERR_FOPEN;
246 }
248 /* get the file size of the local file */
249 hd = curlx_fstat(fileno(hd_src), &file_info);
250 if(hd == -1) {
251 /* cannot open file, bail out */
252 curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n",
253 errno, curlx_strerror(errno, errbuf, sizeof(errbuf)));
254 curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
255 curlx_fclose(hd_src);
256 return TEST_ERR_FSTAT;
257 }
258 curl_mfprintf(stderr, "Set to upload %" CURL_FORMAT_CURL_OFF_T " bytes\n",
259 (curl_off_t)file_info.st_size);
261 res_global_init(CURL_GLOBAL_ALL);
262 if(result != CURLE_OK) {
263 curlx_fclose(hd_src);
264 return result;
265 }
267 easy_init(curl);
269 /* enable uploading */
270 easy_setopt(curl, CURLOPT_UPLOAD, 1L);
272 /* specify target */
273 easy_setopt(curl, CURLOPT_URL, URL);
275 /* go verbose */
276 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
278 /* now specify which file to upload */
279 easy_setopt(curl, CURLOPT_READDATA, hd_src);
281 easy_setopt(curl, CURLOPT_USERPWD, libtest_arg3);
282 easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, test_argv[4]);
283 easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, test_argv[5]);
284 easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
286 easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
288 multi_init(multi);
290 multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, t582_curlSocketCallback);
291 multi_setopt(multi, CURLMOPT_SOCKETDATA, &sockets);
293 multi_setopt(multi, CURLMOPT_TIMERFUNCTION, t582_curlTimerCallback);
294 multi_setopt(multi, CURLMOPT_TIMERDATA, &timeout);
296 multi_add_handle(multi, curl);
298 while(!t582_checkForCompletion(multi, &success)) {
299 fd_set readSet, writeSet;
300 curl_socket_t maxFd = 0;
301 struct timeval tv = { 0 };
302 tv.tv_sec = 10;
304 FD_ZERO(&readSet);
305 FD_ZERO(&writeSet);
306 t582_updateFdSet(&sockets.read, &readSet, &maxFd);
307 t582_updateFdSet(&sockets.write, &writeSet, &maxFd);
309 if(timeout.tv_sec != (time_t)-1) {
310 int usTimeout = curlx_sztosi(t582_getMicroSecondTimeout(&timeout));
311 tv.tv_sec = usTimeout / 1000000;
312 tv.tv_usec = usTimeout % 1000000;
313 }
314 else if(maxFd <= 0) {
315 tv.tv_sec = 0;
316 tv.tv_usec = 100000;
317 }
319 select_test((int)maxFd, &readSet, &writeSet, NULL, &tv);
321 /* Check the sockets for reading / writing */
322 t582_checkFdSet(multi, &sockets.read, &readSet, CURL_CSELECT_IN,
323 "read");
324 t582_checkFdSet(multi, &sockets.write, &writeSet, CURL_CSELECT_OUT,
325 "write");
327 if(timeout.tv_sec != (time_t)-1 &&
328 t582_getMicroSecondTimeout(&timeout) == 0) {
329 /* curl's timer has elapsed. */
330 notifyCurl(multi, CURL_SOCKET_TIMEOUT, 0, "timeout");
331 }
333 abort_on_test_timeout();
334 }
336 if(!success) {
337 curl_mfprintf(stderr, "Error uploading file.\n");
338 result = TEST_ERR_MAJOR_BAD;
339 }
341test_cleanup:
343 /* proper cleanup sequence - type PB */
345 curl_multi_remove_handle(multi, curl);
346 curl_easy_cleanup(curl);
347 curl_multi_cleanup(multi);
348 curl_global_cleanup();
350 /* close the local file */
351 curlx_fclose(hd_src);
353 /* free local memory */
354 curlx_free(sockets.read.sockets);
355 curlx_free(sockets.write.sockets);
357 return result;
Diagnostics4 git calls · 316 ms
CallStatusSizeTime0316 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=311
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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.4 KiB311 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3482
git.response.cache=MISS
git.response.duration_ms=311
git.fetch.wants=50d683398c5e6a1f28f756e148515a25a9fb5f3c
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=3482
git.pkt.payload.max=3461
git.sideband.band1.bytes=3460
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
a5e320e7187c9de8
Request
9f25094d…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format