master
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 "tool_setup.h"
26#ifdef HAVE_SYS_SELECT_H
27#include <sys/select.h>
28#endif
29#ifdef HAVE_POLL_H
30#include <poll.h>
31#elif defined(HAVE_SYS_POLL_H)
32#include <sys/poll.h>
33#endif
35#include "tool_cfgable.h"
36#include "tool_cb_rea.h"
37#include "tool_operate.h"
38#include "tool_msgs.h"
40#ifndef _WIN32
41/* Wait up to a number of milliseconds for socket activity. This function
42 waits on read activity on a file descriptor that is not a socket which
43 makes it not work with select() or poll() on Windows. */
44static void waitfd(int waitms, int fd)
45{
46#ifdef HAVE_POLL
47 struct pollfd set;
49 set.fd = fd;
50 set.events = POLLIN;
51 set.revents = 0;
52 poll(&set, 1, waitms);
53#else
54 fd_set bits;
55 struct timeval timeout;
57 if(fd < FD_SETSIZE) {
58 /* wait this long at the most */
59 timeout.tv_sec = waitms / 1000;
60 timeout.tv_usec = (int)((waitms % 1000) * 1000);
62 FD_ZERO(&bits);
63 FD_SET(fd, &bits);
64 select(fd + 1, &bits, NULL, NULL, &timeout);
65 }
66#endif
67}
68#endif
70/*
71 * callback for CURLOPT_READFUNCTION
72 */
73size_t tool_read_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
74{
75 ssize_t rc = 0;
76 struct per_transfer *per = userdata;
77 struct OperationConfig *config = per->config;
79 if((per->uploadfilesize != -1) &&
80 (per->uploadedsofar == per->uploadfilesize)) {
81 /* done */
82 return 0;
83 }
85 if(config->timeout_ms) {
86 struct curltime now = curlx_now();
87 long msdelta = (long)curlx_timediff_ms(now, per->start);
89 if(msdelta > config->timeout_ms)
90 return 0; /* timeout */
91#ifndef _WIN32
92 else {
93 long w = config->timeout_ms - msdelta;
94 if(w > INT_MAX)
95 w = INT_MAX;
96 waitfd((int)w, per->infd);
97 }
98#endif
99 }
101#ifdef _WIN32
102 /* If we are on Windows, and using `-T .`, then per->infd points to a socket
103 connected to stdin via a reader thread, and needs to be read with recv()
104 Make sure we are in non-blocking mode and infd is not regular stdin
105 On Linux per->infd should be stdin (0) and the block below should not
106 execute */
107 if(per->uploadfile && !strcmp(per->uploadfile, ".") && per->infd > 0) {
108#ifndef CURL_WINDOWS_UWP
109 rc = sread(per->infd, buffer, curlx_uztosi(sz * nmemb));
110 if(rc < 0) {
111 if(SOCK_EAGAIN(SOCKERRNO)) {
112 errno = 0;
113 config->readbusy = TRUE;
114 return CURL_READFUNC_PAUSE;
115 }
117 rc = 0;
118 }
119#else
120 warnf("per->infd != 0: FD == %d. "
121 "This behavior is only supported on desktop Windows", per->infd);
122#endif
123 }
124 else
125#endif /* _WIN32 */
126 {
127 rc = read(per->infd, buffer, sz * nmemb);
128 if(rc < 0) {
129 if(errno == EAGAIN) {
130 errno = 0;
131 config->readbusy = TRUE;
132 return CURL_READFUNC_PAUSE;
133 }
134 /* since size_t is unsigned we cannot return negative values fine */
135 rc = 0;
136 }
137 }
139 if((per->uploadfilesize != -1) &&
140 (per->uploadedsofar + rc > per->uploadfilesize)) {
141 /* do not allow uploading more than originally set out to do */
142 curl_off_t delta = per->uploadedsofar + rc - per->uploadfilesize;
143 warnf("File size larger in the end than when "
144 "started. Dropping at least %" CURL_FORMAT_CURL_OFF_T " bytes",
145 delta);
146 rc = (ssize_t)(per->uploadfilesize - per->uploadedsofar);
147 }
148 config->readbusy = FALSE;
150 /* when select() returned zero here, it timed out */
151 return (size_t)rc;
152}
154/*
155 * callback for CURLOPT_XFERINFOFUNCTION used to unpause busy reads
156 */
157int tool_readbusy_cb(void *clientp,
158 curl_off_t dltotal, curl_off_t dlnow,
159 curl_off_t ultotal, curl_off_t ulnow)
160{
161 struct per_transfer *per = clientp;
162 struct OperationConfig *config = per->config;
163 static curl_off_t ulprev;
165 (void)dltotal;
166 (void)dlnow;
167 (void)ultotal;
168 (void)ulnow;
170 if(config->readbusy) {
171 if(ulprev == ulnow) {
172#ifndef _WIN32
173 waitfd(1, per->infd);
174#else
175 curlx_wait_ms(1); /* sleep */
176#endif
177 }
179 config->readbusy = FALSE;
180 curl_easy_pause(per->curl, CURLPAUSE_CONT);
181 }
183 ulprev = ulnow;
185 return per->noprogress ? 0 : CURL_PROGRESSFUNC_CONTINUE;
186}
Diagnostics4 git calls · 143 ms
CallStatusSizeTime0143 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs 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 · 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=2 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=86Open pack map
fetch2002.2 KiB138 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=138 git.response.bytes=2237 git.response.cache=MISS git.response.duration_ms=138 git.fetch.wants=bf9bd15ad6402312f110a8748da3fa8aaaa3ccea 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=2237 git.pkt.payload.max=2216 git.sideband.band1.bytes=2215 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
- a5e2bcd51c83cfc3
- Request
- 7d1e5eef…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format