Artifactspublic-v0

curl

master
ply4 git calls319 ms289 KiB2 cachedprotocol v2
129 lines3.9 KiBRaw

NAME

curl_multi_fdset - extract file descriptor information from a multi handle

SYNOPSIS

c
#include <curl/curl.h>

CURLMcode curl_multi_fdset(CURLM *multi_handle,
                           fd_set *read_fd_set,
                           fd_set *write_fd_set,
                           fd_set *exc_fd_set,
                           int *max_fd);

DESCRIPTION

This function extracts file descriptor information from a given multi_handle. libcurl returns its fd_set sets. The application can use these to select() on, but be sure to FD_ZERO them before calling this function as curl_multi_fdset(3) only adds its own descriptors, it does not zero or otherwise remove any others. The curl_multi_perform(3) function should be called as soon as one of them is ready to be read from or written to.

The read_fd_set argument should point to an object of type fd_set that on returns specifies the file descriptors to be checked for being ready to read.

The write_fd_set argument should point to an object of type fd_set that on return specifies the file descriptors to be checked for being ready to write.

The exc_fd_set argument should point to an object of type fd_set that on return specifies the file descriptors to be checked for error conditions.

If no file descriptors are set by libcurl, max_fd contain -1 when this function returns. Otherwise it contains the highest descriptor number libcurl set. When libcurl returns -1 in max_fd, it is because libcurl currently does something that is not possible for your application to monitor with a socket and unfortunately you can then not know exactly when the current action is completed using select(). You then need to wait a while before you proceed and call curl_multi_perform(3) anyway. How long to wait? Unless curl_multi_timeout(3) gives you a lower number, we suggest 100 milliseconds or so, but you may want to test it out in your own particular conditions to find a suitable value.

When doing select(), you should use curl_multi_timeout(3) to figure out how long to wait for action. Call curl_multi_perform(3) even if no activity has been seen on the fd_sets after the timeout expires as otherwise internal retries and timeouts may not work as you would think and want.

If one of the sockets used by libcurl happens to be larger than what can be set in an fd_set, which on POSIX systems means that the file descriptor is larger than FD_SETSIZE, then libcurl tries to not set it. Setting a too large file descriptor in an fd_set implies an out of bounds write which can cause crashes, or worse. The effect of NOT storing it might possibly save you from the crash, but makes your program NOT wait for sockets it should wait for...

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  fd_set fdread;
  fd_set fdwrite;
  fd_set fdexcep;
  int maxfd;
  int rc;
  CURLMcode mresult;
  struct timeval timeout = { 1, 0 };

  CURLM *multi = curl_multi_init();

  do {

    /* call curl_multi_perform() */

    FD_ZERO(&fdread);
    FD_ZERO(&fdwrite);
    FD_ZERO(&fdexcep);

    /* get file descriptors from the transfers */
    mresult = curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);

    if(mresult != CURLM_OK) {
      fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mresult);
      break;
    }

    /* wait for activity on one of the sockets */
    rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);

  } while(!mresult);
}

%AVAILABILITY%

RETURN VALUE

This function returns a CURLMcode indicating success or error.

CURLM_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3).

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_multi_fdset
5Section: 3
6Source: libcurl
7See-also:
8 - curl_multi_cleanup (3)
9 - curl_multi_init (3)
10 - curl_multi_perform (3)
11 - curl_multi_timeout (3)
12 - curl_multi_wait (3)
13 - curl_multi_waitfds (3)
14 - select (2)
15Protocol:
16 - All
17Added-in: 7.9.6
18---
20# NAME
22curl_multi_fdset - extract file descriptor information from a multi handle
24# SYNOPSIS
26~~~c
27#include <curl/curl.h>
29CURLMcode curl_multi_fdset(CURLM *multi_handle,
30 fd_set *read_fd_set,
31 fd_set *write_fd_set,
32 fd_set *exc_fd_set,
33 int *max_fd);
34~~~
36# DESCRIPTION
38This function extracts file descriptor information from a given multi_handle.
39libcurl returns its *fd_set* sets. The application can use these to
40select() on, but be sure to *FD_ZERO* them before calling this function as
41curl_multi_fdset(3) only adds its own descriptors, it does not zero or
42otherwise remove any others. The curl_multi_perform(3) function should
43be called as soon as one of them is ready to be read from or written to.
45The *read_fd_set* argument should point to an object of type **fd_set**
46that on returns specifies the file descriptors to be checked for being ready
47to read.
49The *write_fd_set* argument should point to an object of type **fd_set**
50that on return specifies the file descriptors to be checked for being ready to
51write.
53The *exc_fd_set* argument should point to an object of type **fd_set**
54that on return specifies the file descriptors to be checked for error
55conditions.
57If no file descriptors are set by libcurl, *max_fd* contain -1 when this
58function returns. Otherwise it contains the highest descriptor number libcurl
59set. When libcurl returns -1 in *max_fd*, it is because libcurl currently
60does something that is not possible for your application to monitor with a
61socket and unfortunately you can then not know exactly when the current action
62is completed using select(). You then need to wait a while before you proceed
63and call curl_multi_perform(3) anyway. How long to wait? Unless
64curl_multi_timeout(3) gives you a lower number, we suggest 100
65milliseconds or so, but you may want to test it out in your own particular
66conditions to find a suitable value.
68When doing select(), you should use curl_multi_timeout(3) to figure out
69how long to wait for action. Call curl_multi_perform(3) even if no
70activity has been seen on the **fd_sets** after the timeout expires as
71otherwise internal retries and timeouts may not work as you would think and
72want.
74If one of the sockets used by libcurl happens to be larger than what can be
75set in an **fd_set**, which on POSIX systems means that the file descriptor
76is larger than **FD_SETSIZE**, then libcurl tries to not set it. Setting a
77too large file descriptor in an **fd_set** implies an out of bounds write
78which can cause crashes, or worse. The effect of NOT storing it might possibly
79save you from the crash, but makes your program NOT wait for sockets it should
80wait for...
82# %PROTOCOLS%
84# EXAMPLE
86~~~c
87int main(void)
89 fd_set fdread;
90 fd_set fdwrite;
91 fd_set fdexcep;
92 int maxfd;
93 int rc;
94 CURLMcode mresult;
95 struct timeval timeout = { 1, 0 };
97 CURLM *multi = curl_multi_init();
99 do {
101 /* call curl_multi_perform() */
103 FD_ZERO(&fdread);
104 FD_ZERO(&fdwrite);
105 FD_ZERO(&fdexcep);
107 /* get file descriptors from the transfers */
108 mresult = curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
110 if(mresult != CURLM_OK) {
111 fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mresult);
112 break;
113 }
115 /* wait for activity on one of the sockets */
116 rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
118 } while(!mresult);
120~~~
122# %AVAILABILITY%
124# RETURN VALUE
126This function returns a CURLMcode indicating success or error.
128CURLM_OK (0) means everything was OK, non-zero means an error occurred, see
129libcurl-errors(3).
Diagnostics4 git calls · 319 ms
CallStatusSizeTime0319 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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=314
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
fetch2001.7 KiB314 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1790
git.response.cache=MISS
git.response.duration_ms=314
git.fetch.wants=7ab65e424a0d77d97d1077baad701c787a8998a0
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=1790
git.pkt.payload.max=1769
git.sideband.band1.bytes=1768
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
a5e2f7d88cd73a24
Request
0d8a20f2…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format