1curl_multi_fdset(3)             libcurl Manual             curl_multi_fdset(3)
2
3
4

NAME

6       curl_multi_fdset  -  extracts  file descriptor information from a multi
7       handle
8

SYNOPSIS

10       #include <curl/curl.h>
11
12       CURLMcode curl_multi_fdset(CURLM *multi_handle,
13                                  fd_set *read_fd_set,
14                                  fd_set *write_fd_set,
15                                  fd_set *exc_fd_set,
16                                  int *max_fd);
17

DESCRIPTION

19       This  function  extracts  file  descriptor  information  from  a  given
20       multi_handle.  libcurl returns its fd_set sets. The application can use
21       these to select() on, but be sure to FD_ZERO them before  calling  this
22       function  as curl_multi_fdset(3) only adds its own descriptors, it does
23       not zero or otherwise  remove  any  others.  The  curl_multi_perform(3)
24       function  should  be  called as soon as one of them is ready to be read
25       from or written to.
26
27       If the read_fd_set argument is not a null pointer, it points to an  ob‐
28       ject  of  type fd_set that on returns specifies the file descriptors to
29       be checked for being ready to read.
30
31       If the write_fd_set argument is not a null pointer, it points to an ob‐
32       ject of type fd_set that on return specifies the file descriptors to be
33       checked for being ready to write.
34
35       If the exc_fd_set argument is not a null pointer, it points to  an  ob‐
36       ject of type fd_set that on return specifies the file descriptors to be
37       checked for error conditions pending.
38
39       If no file descriptors are set by libcurl, max_fd will contain -1  when
40       this function returns. Otherwise it will contain the highest descriptor
41       number libcurl set. When libcurl returns -1 in max_fd,  it  is  because
42       libcurl currently does something that is not possible for your applica‐
43       tion to monitor with a socket and unfortunately you can then  not  know
44       exactly  when  the current action is completed using select(). You then
45       need to wait a while before you proceed and call  curl_multi_perform(3)
46       anyway.  How  long  to  wait?  Unless curl_multi_timeout(3) gives you a
47       lower number, we suggest 100 milliseconds or so, but you  may  want  to
48       test it out in your own particular conditions to find a suitable value.
49
50       When doing select(), you should use curl_multi_timeout(3) to figure out
51       how long to wait for action. Call curl_multi_perform(3) even if no  ac‐
52       tivity has been seen on the fd_sets after the timeout expires as other‐
53       wise internal retries and timeouts may not work as you would think  and
54       want.
55
56       If  one  of  the sockets used by libcurl happens to be larger than what
57       can be set in an fd_set, which on POSIX systems means that the file de‐
58       scriptor  is  larger  than FD_SETSIZE, then libcurl will try to not set
59       it. Setting a too large file descriptor in an fd_set implies an out  of
60       bounds write which can cause crashes, or worse. The effect of NOT stor‐
61       ing it will possibly save you from the crash, but will make  your  pro‐
62       gram NOT wait for sockets it should wait for...
63

EXAMPLE

65        /* get file descriptors from the transfers */
66        mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
67
68        if(mc != CURLM_OK) {
69          fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
70          break;
71        }
72
73        /* wait for activity on one of the sockets */
74        rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
75

AVAILABILITY

77       Added in 7.9.6
78

RETURN VALUE

80       CURLMcode  type,  general  libcurl  multi  interface  error  code.  See
81       libcurl-errors(3)
82

SEE ALSO

84       curl_multi_cleanup(3),     curl_multi_init(3),      curl_multi_wait(3),
85       curl_multi_timeout(3), curl_multi_perform(3), select(2)
86
87
88
89libcurl 7.82.0                 October 31, 2021            curl_multi_fdset(3)
Impressum