Artifactspublic-v0

curl

master
ply4 git calls173 ms289 KiB2 cachedprotocol v2
201 lines5.8 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/* <DESC>
25 * A basic application source code using the multi interface doing two
26 * transfers in parallel without curl_multi_wait/poll.
27 * </DESC>
28 */
29#include <stdio.h>
30#include <string.h>
32/* somewhat Unix-specific */
33#ifndef _WIN32
34#include <sys/time.h>
35#include <unistd.h>
36#endif
38#include <curl/curl.h>
40/*
41 * Download an HTTP file and upload an FTP file simultaneously.
42 */
44#define HTTP_HANDLE 0 /* Index for the HTTP transfer */
45#define FTP_HANDLE 1 /* Index for the FTP transfer */
46#define HANDLECOUNT 2 /* Number of simultaneous transfers */
48int main(void)
50 CURL *curl[HANDLECOUNT];
51 CURLM *multi;
53 int i;
55 CURLcode result = curl_global_init(CURL_GLOBAL_ALL);
56 if(result != CURLE_OK)
57 return (int)result;
59 /* Allocate one curl handle per transfer */
60 for(i = 0; i < HANDLECOUNT; i++)
61 curl[i] = curl_easy_init();
63 /* set the options (I left out a few, you get the point anyway) */
64 curl_easy_setopt(curl[HTTP_HANDLE], CURLOPT_URL, "https://example.com");
66 curl_easy_setopt(curl[FTP_HANDLE], CURLOPT_URL, "ftp://example.com");
67 curl_easy_setopt(curl[FTP_HANDLE], CURLOPT_UPLOAD, 1L);
69 /* init a multi stack */
70 multi = curl_multi_init();
71 if(multi) {
73 int still_running = 0; /* keep number of running handles */
75 CURLMsg *msg; /* for picking up messages with the transfer status */
76 int msgs_left; /* how many messages are left */
78 /* add the individual transfers */
79 for(i = 0; i < HANDLECOUNT; i++)
80 curl_multi_add_handle(multi, curl[i]);
82 /* we start some action by calling perform right away */
83 curl_multi_perform(multi, &still_running);
85 while(still_running) {
87 struct timeval timeout;
88 int rc; /* select() return code */
89 CURLMcode mresult; /* curl_multi_fdset() return code */
91 fd_set fdread;
92 fd_set fdwrite;
93 fd_set fdexcep;
94 int maxfd = -1;
96 long curl_timeo = -1;
98 FD_ZERO(&fdread);
99 FD_ZERO(&fdwrite);
100 FD_ZERO(&fdexcep);
102 /* set a suitable timeout to play around with */
103 timeout.tv_sec = 1;
104 timeout.tv_usec = 0;
106 curl_multi_timeout(multi, &curl_timeo);
107 if(curl_timeo >= 0) {
108#if defined(MSDOS) || defined(__AMIGA__)
109 timeout.tv_sec = (time_t)(curl_timeo / 1000);
110#else
111 timeout.tv_sec = curl_timeo / 1000;
112#endif
113 if(timeout.tv_sec > 1)
114 timeout.tv_sec = 1;
115 else
116#if defined(MSDOS) || defined(__AMIGA__)
117 timeout.tv_usec = (time_t)(curl_timeo % 1000) * 1000;
118#else
119 timeout.tv_usec = (int)(curl_timeo % 1000) * 1000;
120#endif
121 }
123 /* get file descriptors from the transfers */
124 mresult = curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
126 if(mresult != CURLM_OK) {
127 fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mresult);
128 break;
129 }
131 /* On success the value of maxfd is guaranteed to be >= -1. We call
132 select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
133 no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
134 to sleep 100ms, which is the minimum suggested value in the
135 curl_multi_fdset() doc. */
137 if(maxfd == -1) {
138#ifdef _WIN32
139 Sleep(100);
140 rc = 0;
141#else
142 /* Portable sleep for platforms other than Windows. */
143 struct timeval wait = { 0 };
144 wait.tv_usec = 100 * 1000; /* 100ms */
145 rc = select(0, NULL, NULL, NULL, &wait);
146#endif
147 }
148 else {
149 /* Note that on some platforms 'timeout' may be modified by select().
150 If you need access to the original value save a copy beforehand. */
151 rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
152 }
154 switch(rc) {
155 case -1:
156 /* select error */
157 break;
158 case 0: /* timeout */
159 default: /* action */
160 curl_multi_perform(multi, &still_running);
161 break;
162 }
163 }
165 /* See how the transfers went */
166 /* !checksrc! disable EQUALSNULL 1 */
167 while((msg = curl_multi_info_read(multi, &msgs_left)) != NULL) {
168 if(msg->msg == CURLMSG_DONE) {
169 int idx;
171 /* Find out which handle this message is about */
172 for(idx = 0; idx < HANDLECOUNT; idx++) {
173 int found = (msg->easy_handle == curl[idx]);
174 if(found)
175 break;
176 }
178 switch(idx) {
179 case HTTP_HANDLE:
180 printf("HTTP transfer completed with status %d\n",
181 (int)msg->data.result);
182 break;
183 case FTP_HANDLE:
184 printf("FTP transfer completed with status %d\n",
185 (int)msg->data.result);
186 break;
187 }
188 }
189 }
191 curl_multi_cleanup(multi);
192 }
194 /* Free the curl handles */
195 for(i = 0; i < HANDLECOUNT; i++)
196 curl_easy_cleanup(curl[i]);
198 curl_global_cleanup();
200 return 0;
Diagnostics4 git calls · 173 ms
CallStatusSizeTime0173 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 · 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=2
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
fetch2002.3 KiB168 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=168
git.response.bytes=2401
git.response.cache=MISS
git.response.duration_ms=168
git.fetch.wants=bd23866d6f8cacf054166eed327dc6dedb1dbb89
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=2401
git.pkt.payload.max=2380
git.sideband.band1.bytes=2379
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
a5e2c30aef97aedd
Request
ab05fb30…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format