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 "curl_setup.h"
26#ifdef HAVE_SYS_SELECT_H
27#include <sys/select.h>
28#elif defined(HAVE_UNISTD_H)
29#include <unistd.h>
30#endif
32#include "urldata.h"
33#include "connect.h"
34#include "select.h"
35#include "curl_trc.h"
36#include "curlx/timediff.h"
37#include "curlx/wait.h"
39#ifndef HAVE_POLL /* use select() */
40/*
41 * This is a wrapper around select() to aid in Windows compatibility. A
42 * negative timeout value makes this function wait indefinitely, unless no
43 * valid file descriptor is given, when this happens the negative timeout is
44 * ignored and the function times out immediately.
45 *
46 * Return values:
47 * -1 = system call error or fd >= FD_SETSIZE
48 * 0 = timeout
49 * N = number of signalled file descriptors
50 */
51static int our_select(curl_socket_t maxfd, /* highest socket number */
52 fd_set *fds_read, /* sockets ready for reading */
53 fd_set *fds_write, /* sockets ready for writing */
54 fd_set *fds_err, /* sockets with errors */
55 timediff_t timeout_ms) /* milliseconds to wait */
56{
57 struct timeval pending_tv;
58 struct timeval *ptimeout;
60#ifdef USE_WINSOCK
61 /* Winsock select() cannot handle zero events. See the comment below. */
62 if((!fds_read || fds_read->fd_count == 0) &&
63 (!fds_write || fds_write->fd_count == 0) &&
64 (!fds_err || fds_err->fd_count == 0)) {
65 /* no sockets, wait */
66 return curlx_wait_ms(timeout_ms);
67 }
68#endif
70 ptimeout = curlx_mstotv(&pending_tv, timeout_ms);
72#ifdef USE_WINSOCK
73 /* Winsock select() must not be called with an fd_set that contains zero
74 fd flags, or it will return WSAEINVAL. It also cannot be called with
75 no fd_sets at all! From the documentation:
77 Any two of the parameters, readfds, writefds, or exceptfds, can be
78 given as null. At least one must be non-null, and any non-null
79 descriptor set must contain at least one handle to a socket.
81 It is unclear why Winsock does not handle this for us instead of
82 calling this an error. Luckily, with Winsock, we can _also_ ask how
83 many bits are set on an fd_set. Therefore, let's check it beforehand.
84 */
85 return select((int)maxfd + 1,
86 fds_read && fds_read->fd_count ? fds_read : NULL,
87 fds_write && fds_write->fd_count ? fds_write : NULL,
88 fds_err && fds_err->fd_count ? fds_err : NULL, ptimeout);
89#else
90 return select((int)maxfd + 1, fds_read, fds_write, fds_err, ptimeout);
91#endif
92}
94#endif
96/*
97 * Wait for read or write events on a set of file descriptors. It uses poll()
98 * when poll() is available, in order to avoid limits with FD_SETSIZE,
99 * otherwise select() is used. An error is returned if select() is being used
100 * and a file descriptor is too large for FD_SETSIZE.
101 *
102 * A negative timeout value makes this function wait indefinitely, unless no
103 * valid file descriptor is given, when this happens the negative timeout is
104 * ignored and the function times out immediately.
105 *
106 * Return values:
107 * -1 = system call error or fd >= FD_SETSIZE
108 * 0 = timeout
109 * [bitmask] = action as described below
110 *
111 * CURL_CSELECT_IN - first socket is readable
112 * CURL_CSELECT_IN2 - second socket is readable
113 * CURL_CSELECT_OUT - write socket is writable
114 * CURL_CSELECT_ERR - an error condition occurred
115 */
116int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
117 curl_socket_t readfd1,
118 curl_socket_t writefd, /* socket to write to */
119 timediff_t timeout_ms) /* milliseconds to wait */
120{
121 struct pollfd pfd[3];
122 int num;
123 int r;
125 if((readfd0 == CURL_SOCKET_BAD) && (readfd1 == CURL_SOCKET_BAD) &&
126 (writefd == CURL_SOCKET_BAD)) {
127 /* no sockets, wait */
128 return curlx_wait_ms(timeout_ms);
129 }
131 /* Avoid initial timestamp, avoid curlx_now() call, when elapsed
132 time in this function does not need to be measured. This happens
133 when function is called with a zero timeout or a negative timeout
134 value indicating a blocking call should be performed. */
136 num = 0;
137 if(readfd0 != CURL_SOCKET_BAD) {
138 pfd[num].fd = readfd0;
139 pfd[num].events = POLLRDNORM | POLLIN | POLLRDBAND | POLLPRI;
140 pfd[num].revents = 0;
141 num++;
142 }
143 if(readfd1 != CURL_SOCKET_BAD) {
144 pfd[num].fd = readfd1;
145 pfd[num].events = POLLRDNORM | POLLIN | POLLRDBAND | POLLPRI;
146 pfd[num].revents = 0;
147 num++;
148 }
149 if(writefd != CURL_SOCKET_BAD) {
150 pfd[num].fd = writefd;
151 pfd[num].events = POLLWRNORM | POLLOUT | POLLPRI;
152 pfd[num].revents = 0;
153 num++;
154 }
156 r = Curl_poll(pfd, (unsigned int)num, timeout_ms);
157 if(r <= 0)
158 return r;
160 r = 0;
161 num = 0;
162 if(readfd0 != CURL_SOCKET_BAD) {
163 if(pfd[num].revents & (POLLRDNORM | POLLIN | POLLERR | POLLHUP))
164 r |= CURL_CSELECT_IN;
165 if(pfd[num].revents & (POLLPRI | POLLNVAL))
166 r |= CURL_CSELECT_ERR;
167 num++;
168 }
169 if(readfd1 != CURL_SOCKET_BAD) {
170 if(pfd[num].revents & (POLLRDNORM | POLLIN | POLLERR | POLLHUP))
171 r |= CURL_CSELECT_IN2;
172 if(pfd[num].revents & (POLLPRI | POLLNVAL))
173 r |= CURL_CSELECT_ERR;
174 num++;
175 }
176 if(writefd != CURL_SOCKET_BAD) {
177 if(pfd[num].revents & (POLLWRNORM | POLLOUT))
178 r |= CURL_CSELECT_OUT;
179 if(pfd[num].revents & (POLLERR | POLLHUP | POLLPRI | POLLNVAL))
180 r |= CURL_CSELECT_ERR;
181 }
183 return r;
184}
186/*
187 * This is a wrapper around poll(). If poll() does not exist, then
188 * select() is used instead. An error is returned if select() is
189 * being used and a file descriptor is too large for FD_SETSIZE.
190 * A negative timeout value makes this function wait indefinitely,
191 * unless no valid file descriptor is given, when this happens the
192 * negative timeout is ignored and the function times out immediately.
193 *
194 * Return values:
195 * -1 = system call error or fd >= FD_SETSIZE
196 * 0 = timeout
197 * N = number of structures with non zero revent fields
198 */
199int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
200{
201#ifdef HAVE_POLL
202 int pending_ms;
203#else
204 fd_set fds_read;
205 fd_set fds_write;
206 fd_set fds_err;
207 curl_socket_t maxfd;
208#endif
209 bool fds_none = TRUE;
210 unsigned int i;
211 int r;
213 if(ufds) {
214 for(i = 0; i < nfds; i++) {
215 if(ufds[i].fd != CURL_SOCKET_BAD) {
216 fds_none = FALSE;
217 break;
218 }
219 }
220 }
221 if(fds_none) {
222 /* no sockets, wait */
223 return curlx_wait_ms(timeout_ms);
224 }
226 /* Avoid initial timestamp, avoid curlx_now() call, when elapsed
227 time in this function does not need to be measured. This happens
228 when function is called with a zero timeout or a negative timeout
229 value indicating a blocking call should be performed. */
231#ifdef HAVE_POLL
233 /* prevent overflow, timeout_ms is typecast to int. */
234#if TIMEDIFF_T_MAX > INT_MAX
235 if(timeout_ms > INT_MAX)
236 timeout_ms = INT_MAX;
237#endif
238 if(timeout_ms > 0)
239 pending_ms = (int)timeout_ms;
240 else if(timeout_ms < 0)
241 pending_ms = -1;
242 else
243 pending_ms = 0;
244 r = poll(ufds, nfds, pending_ms);
245 if(r <= 0) {
246 if((r == -1) && (SOCKERRNO == SOCKEINTR))
247 /* make EINTR from select or poll not a "lethal" error */
248 r = 0;
249 return r;
250 }
252 for(i = 0; i < nfds; i++) {
253 if(ufds[i].fd == CURL_SOCKET_BAD)
254 continue;
255 if(ufds[i].revents & POLLHUP)
256 ufds[i].revents |= POLLIN;
257 if(ufds[i].revents & POLLERR)
258 ufds[i].revents |= POLLIN | POLLOUT;
259 }
261#else /* !HAVE_POLL */
263 FD_ZERO(&fds_read);
264 FD_ZERO(&fds_write);
265 FD_ZERO(&fds_err);
266 maxfd = (curl_socket_t)-1;
268 for(i = 0; i < nfds; i++) {
269 ufds[i].revents = 0;
270 if(ufds[i].fd == CURL_SOCKET_BAD)
271 continue;
272 VERIFY_SOCK(ufds[i].fd);
273 if(ufds[i].events & (POLLIN | POLLOUT | POLLPRI |
274 POLLRDNORM | POLLWRNORM | POLLRDBAND)) {
275 if(ufds[i].fd > maxfd)
276 maxfd = ufds[i].fd;
277 if(ufds[i].events & (POLLRDNORM | POLLIN))
278 FD_SET(ufds[i].fd, &fds_read);
279 if(ufds[i].events & (POLLWRNORM | POLLOUT))
280 FD_SET(ufds[i].fd, &fds_write);
281 if(ufds[i].events & (POLLRDBAND | POLLPRI))
282 FD_SET(ufds[i].fd, &fds_err);
283 }
284 }
286 /* Note also that Winsock ignores the first argument, so we do not worry
287 about the fact that maxfd is computed incorrectly with Winsock (since
288 curl_socket_t is unsigned in such cases and thus -1 is the largest
289 value). */
290 r = our_select(maxfd, &fds_read, &fds_write, &fds_err, timeout_ms);
291 if(r <= 0) {
292 if((r == -1) && (SOCKERRNO == SOCKEINTR))
293 /* make EINTR from select or poll not a "lethal" error */
294 r = 0;
295 return r;
296 }
298 r = 0;
299 for(i = 0; i < nfds; i++) {
300 ufds[i].revents = 0;
301 if(ufds[i].fd == CURL_SOCKET_BAD)
302 continue;
303 if(FD_ISSET(ufds[i].fd, &fds_read)) {
304 if(ufds[i].events & POLLRDNORM)
305 ufds[i].revents |= POLLRDNORM;
306 if(ufds[i].events & POLLIN)
307 ufds[i].revents |= POLLIN;
308 }
309 if(FD_ISSET(ufds[i].fd, &fds_write)) {
310 if(ufds[i].events & POLLWRNORM)
311 ufds[i].revents |= POLLWRNORM;
312 if(ufds[i].events & POLLOUT)
313 ufds[i].revents |= POLLOUT;
314 }
315 if(FD_ISSET(ufds[i].fd, &fds_err)) {
316 if(ufds[i].events & POLLRDBAND)
317 ufds[i].revents |= POLLRDBAND;
318 if(ufds[i].events & POLLPRI)
319 ufds[i].revents |= POLLPRI;
320 }
321 if(ufds[i].revents)
322 r++;
323 }
325#endif /* HAVE_POLL */
327 return r;
328}
330void Curl_pollfds_init(struct curl_pollfds *cpfds,
331 struct pollfd *static_pfds,
332 unsigned int static_count)
333{
334 DEBUGASSERT(cpfds);
335 memset(cpfds, 0, sizeof(*cpfds));
336 if(static_pfds && static_count) {
337 cpfds->pfds = static_pfds;
338 cpfds->count = static_count;
339 }
340}
342void Curl_pollfds_reset(struct curl_pollfds *cpfds)
343{
344 cpfds->n = 0;
345}
347void Curl_pollfds_cleanup(struct curl_pollfds *cpfds)
348{
349 DEBUGASSERT(cpfds);
350 if(cpfds->allocated_pfds) {
351 curlx_safefree(cpfds->pfds);
352 cpfds->count = 0;
353 cpfds->allocated_pfds = FALSE;
354 }
355 cpfds->n = 0;
356}
358static CURLcode cpfds_increase(struct curl_pollfds *cpfds, unsigned int inc)
359{
360 struct pollfd *new_fds;
361 unsigned int new_count = cpfds->count + inc;
363 new_fds = curlx_calloc(new_count, sizeof(struct pollfd));
364 if(!new_fds)
365 return CURLE_OUT_OF_MEMORY;
367 memcpy(new_fds, cpfds->pfds, cpfds->count * sizeof(struct pollfd));
368 if(cpfds->allocated_pfds)
369 curlx_free(cpfds->pfds);
370 cpfds->pfds = new_fds;
371 cpfds->count = new_count;
372 cpfds->allocated_pfds = TRUE;
373 return CURLE_OK;
374}
376static CURLcode cpfds_add_sock(struct curl_pollfds *cpfds,
377 curl_socket_t sock, short events, bool fold)
378{
379 int i;
381 if(fold && cpfds->n <= INT_MAX) {
382 for(i = (int)cpfds->n - 1; i >= 0; --i) {
383 if(sock == cpfds->pfds[i].fd) {
384 cpfds->pfds[i].events |= events;
385 return CURLE_OK;
386 }
387 }
388 }
389 /* not folded, add new entry */
390 if(cpfds->n >= cpfds->count && cpfds_increase(cpfds, 100))
391 return CURLE_OUT_OF_MEMORY;
392 cpfds->pfds[cpfds->n].fd = sock;
393 cpfds->pfds[cpfds->n].events = events;
394 ++cpfds->n;
395 return CURLE_OK;
396}
398CURLcode Curl_pollfds_add_sock(struct curl_pollfds *cpfds,
399 curl_socket_t sock, short events)
400{
401 return cpfds_add_sock(cpfds, sock, events, FALSE);
402}
404CURLcode Curl_pollfds_add_ps(struct curl_pollfds *cpfds,
405 struct easy_pollset *ps)
406{
407 size_t i;
409 DEBUGASSERT(cpfds);
410 DEBUGASSERT(ps);
411 for(i = 0; i < ps->n; i++) {
412 short events = 0;
413 if(ps->actions[i] & CURL_POLL_IN)
414 events |= POLLIN;
415 if(ps->actions[i] & CURL_POLL_OUT)
416 events |= POLLOUT;
417 if(events && cpfds_add_sock(cpfds, ps->sockets[i], events, TRUE))
418 return CURLE_OUT_OF_MEMORY;
419 }
420 return CURLE_OK;
421}
423void Curl_waitfds_init(struct Curl_waitfds *cwfds,
424 struct curl_waitfd *static_wfds,
425 unsigned int static_count)
426{
427 DEBUGASSERT(cwfds);
428 DEBUGASSERT(static_wfds || !static_count);
429 memset(cwfds, 0, sizeof(*cwfds));
430 cwfds->wfds = static_wfds;
431 cwfds->count = static_count;
432}
434static unsigned int cwfds_add_sock(struct Curl_waitfds *cwfds,
435 curl_socket_t sock, short events)
436{
437 int i;
438 if(!cwfds->wfds) {
439 DEBUGASSERT(!cwfds->count && !cwfds->n);
440 return 1;
441 }
442 if(cwfds->n <= INT_MAX) {
443 for(i = (int)cwfds->n - 1; i >= 0; --i) {
444 if(sock == cwfds->wfds[i].fd) {
445 cwfds->wfds[i].events |= events;
446 return 0;
447 }
448 }
449 }
450 /* not folded, add new entry */
451 if(cwfds->n < cwfds->count) {
452 cwfds->wfds[cwfds->n].fd = sock;
453 cwfds->wfds[cwfds->n].events = events;
454 ++cwfds->n;
455 }
456 return 1;
457}
459unsigned int Curl_waitfds_add_ps(struct Curl_waitfds *cwfds,
460 struct easy_pollset *ps)
461{
462 size_t i;
463 unsigned int need = 0;
465 DEBUGASSERT(cwfds);
466 DEBUGASSERT(ps);
467 for(i = 0; i < ps->n; i++) {
468 short events = 0;
469 if(ps->actions[i] & CURL_POLL_IN)
470 events |= CURL_WAIT_POLLIN;
471 if(ps->actions[i] & CURL_POLL_OUT)
472 events |= CURL_WAIT_POLLOUT;
473 if(events)
474 need += cwfds_add_sock(cwfds, ps->sockets[i], events);
475 }
476 return need;
477}
479void Curl_pollset_reset(struct easy_pollset *ps)
480{
481#ifdef DEBUGBUILD
482 DEBUGASSERT(ps->init == CURL_EASY_POLLSET_MAGIC);
483#endif
484 ps->n = 0;
485}
487void Curl_pollset_init(struct easy_pollset *ps)
488{
489#ifdef DEBUGBUILD
490 ps->init = CURL_EASY_POLLSET_MAGIC;
491#endif
492 ps->sockets = ps->def_sockets;
493 ps->actions = ps->def_actions;
494 ps->count = CURL_ARRAYSIZE(ps->def_sockets);
495 ps->n = 0;
496 Curl_pollset_reset(ps);
497}
499struct easy_pollset *Curl_pollset_create(void)
500{
501 struct easy_pollset *ps = curlx_calloc(1, sizeof(*ps));
502 if(ps)
503 Curl_pollset_init(ps);
504 return ps;
505}
507void Curl_pollset_cleanup(struct easy_pollset *ps)
508{
509#ifdef DEBUGBUILD
510 DEBUGASSERT(ps->init == CURL_EASY_POLLSET_MAGIC);
511#endif
512 if(ps->sockets != ps->def_sockets) {
513 curlx_free(ps->sockets);
514 ps->sockets = ps->def_sockets;
515 }
516 if(ps->actions != ps->def_actions) {
517 curlx_free(ps->actions);
518 ps->actions = ps->def_actions;
519 }
520 ps->count = CURL_ARRAYSIZE(ps->def_sockets);
521 Curl_pollset_reset(ps);
522}
524void Curl_pollset_move(struct easy_pollset *to, struct easy_pollset *from)
525{
526 Curl_pollset_cleanup(to); /* deallocate anything in to */
527 if(from->sockets != from->def_sockets) {
528 DEBUGASSERT(from->actions != from->def_actions);
529 to->sockets = from->sockets;
530 to->actions = from->actions;
531 to->count = from->count;
532 to->n = from->n;
533 Curl_pollset_init(from);
534 }
535 else {
536 DEBUGASSERT(to->sockets == to->def_sockets);
537 DEBUGASSERT(to->actions == to->def_actions);
538 memcpy(to->sockets, from->sockets, to->count * sizeof(to->sockets[0]));
539 memcpy(to->actions, from->actions, to->count * sizeof(to->actions[0]));
540 to->n = from->n;
541 Curl_pollset_init(from);
542 }
543}
545/**
546 *
547 */
548CURLcode Curl_pollset_change(struct Curl_easy *data,
549 struct easy_pollset *ps, curl_socket_t sock,
550 int add_flags, int remove_flags)
551{
552 unsigned int i;
554#ifdef DEBUGBUILD
555 DEBUGASSERT(ps->init == CURL_EASY_POLLSET_MAGIC);
556#endif
558 DEBUGASSERT(VALID_SOCK(sock));
559 if(!VALID_SOCK(sock))
560 return CURLE_BAD_FUNCTION_ARGUMENT;
562 DEBUGASSERT(add_flags <= (CURL_POLL_IN | CURL_POLL_OUT));
563 DEBUGASSERT(remove_flags <= (CURL_POLL_IN | CURL_POLL_OUT));
564 DEBUGASSERT((add_flags & remove_flags) == 0); /* no overlap */
565 for(i = 0; i < ps->n; ++i) {
566 if(ps->sockets[i] == sock) {
567 ps->actions[i] &= (unsigned char)(~remove_flags);
568 ps->actions[i] |= (unsigned char)add_flags;
569 /* all gone? remove socket */
570 if(!ps->actions[i]) {
571 if((i + 1) < ps->n) {
572 memmove(&ps->sockets[i], &ps->sockets[i + 1],
573 (ps->n - (i + 1)) * sizeof(ps->sockets[0]));
574 memmove(&ps->actions[i], &ps->actions[i + 1],
575 (ps->n - (i + 1)) * sizeof(ps->actions[0]));
576 }
577 --ps->n;
578 }
579 return CURLE_OK;
580 }
581 }
582 /* not present */
583 if(add_flags) {
584 if(i >= ps->count) { /* need to grow */
585 unsigned int new_count = CURLMAX(ps->count * 2, 8);
586 curl_socket_t *nsockets;
587 unsigned char *nactions;
589 CURL_TRC_M(data, "growing pollset capacity from %u to %u",
590 ps->count, new_count);
591 if(new_count <= ps->count)
592 return CURLE_OUT_OF_MEMORY;
593 nsockets = curlx_calloc(new_count, sizeof(nsockets[0]));
594 if(!nsockets)
595 return CURLE_OUT_OF_MEMORY;
596 nactions = curlx_calloc(new_count, sizeof(nactions[0]));
597 if(!nactions) {
598 curlx_free(nsockets);
599 return CURLE_OUT_OF_MEMORY;
600 }
601 memcpy(nsockets, ps->sockets, ps->count * sizeof(ps->sockets[0]));
602 memcpy(nactions, ps->actions, ps->count * sizeof(ps->actions[0]));
603 if(ps->sockets != ps->def_sockets)
604 curlx_free(ps->sockets);
605 ps->sockets = nsockets;
606 if(ps->actions != ps->def_actions)
607 curlx_free(ps->actions);
608 ps->actions = nactions;
609 ps->count = new_count;
610 }
611 DEBUGASSERT(i < ps->count);
612 if(i < ps->count) {
613 ps->sockets[i] = sock;
614 ps->actions[i] = (unsigned char)add_flags;
615 ps->n = i + 1;
616 }
617 }
618 return CURLE_OK;
619}
621CURLcode Curl_pollset_set(struct Curl_easy *data,
622 struct easy_pollset *ps, curl_socket_t sock,
623 bool do_in, bool do_out)
624{
625 return Curl_pollset_change(data, ps, sock,
626 (do_in ? CURL_POLL_IN : 0) |
627 (do_out ? CURL_POLL_OUT : 0),
628 (!do_in ? CURL_POLL_IN : 0) |
629 (!do_out ? CURL_POLL_OUT : 0));
630}
632void Curl_pollset_remove(struct easy_pollset *ps, curl_socket_t sock)
633{
634 unsigned int i;
635 for(i = 0; i < ps->n; ++i) {
636 if(ps->sockets[i] == sock) {
637 if((i + 1) < ps->n) {
638 memmove(&ps->sockets[i], &ps->sockets[i + 1],
639 (ps->n - (i + 1)) * sizeof(ps->sockets[0]));
640 memmove(&ps->actions[i], &ps->actions[i + 1],
641 (ps->n - (i + 1)) * sizeof(ps->actions[0]));
642 }
643 --ps->n;
644 return;
645 }
646 }
647}
649/*
650 * Return values:
651 * -1 = error
652 * 0 = timeout
653 * N = number of structures with non zero revent fields
654 */
655int Curl_pollset_poll(struct Curl_easy *data,
656 struct easy_pollset *ps,
657 timediff_t timeout_ms)
658{
659 struct pollfd *pfds;
660 unsigned int i, npfds;
661 int rc;
663 (void)data;
664 DEBUGASSERT(data);
665 DEBUGASSERT(data->conn);
667 if(!ps->n)
668 return curlx_wait_ms(timeout_ms);
670 pfds = curlx_calloc(ps->n, sizeof(*pfds));
671 if(!pfds)
672 return -1;
674 npfds = 0;
675 for(i = 0; i < ps->n; ++i) {
676 short events = 0;
677 if(ps->actions[i] & CURL_POLL_IN) {
678 events |= POLLIN;
679 }
680 if(ps->actions[i] & CURL_POLL_OUT) {
681 events |= POLLOUT;
682 }
683 if(events) {
684 pfds[npfds].fd = ps->sockets[i];
685 pfds[npfds].events = events;
686 ++npfds;
687 }
688 }
690 rc = Curl_poll(pfds, npfds, timeout_ms);
691 curlx_free(pfds);
692 return rc;
693}
695void Curl_pollset_check(struct Curl_easy *data,
696 struct easy_pollset *ps, curl_socket_t sock,
697 bool *pwant_read, bool *pwant_write)
698{
699 unsigned int i;
701 (void)data;
702 DEBUGASSERT(VALID_SOCK(sock));
703 for(i = 0; i < ps->n; ++i) {
704 if(ps->sockets[i] == sock) {
705 *pwant_read = !!(ps->actions[i] & CURL_POLL_IN);
706 *pwant_write = !!(ps->actions[i] & CURL_POLL_OUT);
707 return;
708 }
709 }
710 *pwant_read = *pwant_write = FALSE;
711}
713bool Curl_pollset_want_recv(struct Curl_easy *data,
714 struct easy_pollset *ps,
715 curl_socket_t sock)
716{
717 unsigned int i;
718 (void)data;
719 for(i = 0; i < ps->n; ++i) {
720 if((ps->sockets[i] == sock) && (ps->actions[i] & CURL_POLL_IN))
721 return TRUE;
722 }
723 return FALSE;
724}
726bool Curl_pollset_want_send(struct Curl_easy *data,
727 struct easy_pollset *ps,
728 curl_socket_t sock)
729{
730 unsigned int i;
731 (void)data;
732 for(i = 0; i < ps->n; ++i) {
733 if((ps->sockets[i] == sock) && (ps->actions[i] & CURL_POLL_OUT))
734 return TRUE;
735 }
736 return FALSE;
737}
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 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 · 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 · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=5 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
fetch2005.6 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=5704 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=3e45fda780189410c17b23631ce88fa15bfddfbd 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=5704 git.pkt.payload.max=5683 git.sideband.band1.bytes=5682 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
- a5e22c173d552a83
- Request
- 48c2f61f…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format