1libcurl-multi(3)            libcurl multi interface           libcurl-multi(3)
2
3
4

NAME

6       libcurl-multi - how to use the multi interface
7

DESCRIPTION

9       This is an overview on how to use the libcurl multi interface in your C
10       programs. There are specific man pages for each function  mentioned  in
11       here.  There's  also  the  libcurl-tutorial(3)  man page for a complete
12       tutorial to programming with libcurl and the libcurl-easy(3)  man  page
13       for an overview of the libcurl easy interface.
14
15       All functions in the multi interface are prefixed with curl_multi.
16

OBJECTIVES

18       The  multi  interface  offers several abilities that the easy interface
19       doesn't.  They are mainly:
20
21       1. Enable a "pull" interface. The application that uses libcurl decides
22       where and when to ask libcurl to get/send data.
23
24       2.  Enable  multiple  simultaneous transfers in the same thread without
25       making it complicated for the application.
26
27       3. Enable the application to wait for action on its own  file  descrip‐
28       tors and curl's file descriptors simultaneous easily.
29

ONE MULTI HANDLE MANY EASY HANDLES

31       To use the multi interface, you must first create a 'multi handle' with
32       curl_multi_init(3). This handle is then used as input  to  all  further
33       curl_multi_* functions.
34
35       Each  single  transfer is built up with an easy handle. You must create
36       them, and setup the appropriate options for each easy handle,  as  out‐
37       lined in the libcurl(3) man page, using curl_easy_setopt(3).
38
39       When  the  easy  handle  is setup for a transfer, then instead of using
40       curl_easy_perform(3) (as when using the easy interface for  transfers),
41       you  should  instead  add  the  easy  handle  to the multi handle using
42       curl_multi_add_handle(3). The multi handle is sometimes referred to  as
43       a  ´multi stack´ because of the fact that it may hold a large amount of
44       easy handles.
45
46       Should you change your mind, the easy handle is again removed from  the
47       multi  stack  using  curl_multi_remove_handle(3). Once removed from the
48       multi handle, you can again use other  easy  interface  functions  like
49       curl_easy_perform(3) on the handle or whatever you think is necessary.
50
51       Adding the easy handle to the multi handle does not start the transfer.
52       Remember that one of the main ideas with this interface is to let  your
53       application  drive. You drive the transfers by invoking curl_multi_per‐
54       form(3). libcurl will then transfer data if there is anything available
55       to transfer. It'll use the callbacks and everything else you have setup
56       in the individual easy handles. It'll  transfer  data  on  all  current
57       transfers  in  the  multi stack that are ready to transfer anything. It
58       may be all, it may be none.
59
60       Your application can acquire knowledge from libcurl when it would  like
61       to  get  invoked  to transfer data, so that you don't have to busy-loop
62       and call that  curl_multi_perform(3)  like  crazy.  curl_multi_fdset(3)
63       offers an interface using which you can extract fd_sets from libcurl to
64       use in select() or poll() calls in order to get to know when the trans‐
65       fers  in  the multi stack might need attention. This also makes it very
66       easy for your program to wait  for  input  on  your  own  private  file
67       descriptors  at  the  same  time or perhaps timeout every now and then,
68       should you want that.
69
70       A little note here about the return codes from the multi functions, and
71       especially     the     curl_multi_perform(3):     if     you    receive
72       CURLM_CALL_MULTI_PERFORM, this basically means  that  you  should  call
73       curl_multi_perform(3)  again,  before you select() on more actions. You
74       don't have to do it immediately, but the return code means that libcurl
75       may  have  more data available to return or that there may be more data
76       to send off before it is "satisfied".
77
78       curl_multi_perform(3) stores the number of still running  transfers  in
79       one of its input arguments, and by reading that you can figure out when
80       all the transfers in the multi handles are done. 'done' does  not  mean
81       successful. One or more of the transfers may have failed. Tracking when
82       this number changes, you know when one or more transfers are done.
83
84       To get information about completed transfers, to figure out success  or
85       not  and  similar,  curl_multi_info_read(3)  should  be  called. It can
86       return a message about a current or previous transfer. Repeated invokes
87       of the function get more messages until the message queue is empty. The
88       information you receive there includes an easy handle pointer which you
89       may use to identify which easy handle the information regards.
90
91       When  a  single  transfer  is  completed, the easy handle is still left
92       added to the multi stack. You need to first remove the easy handle with
93       curl_multi_remove_handle(3)      and     then     close     it     with
94       curl_easy_cleanup(3), or possibly set new options  to  it  and  add  it
95       again with curl_multi_add_handle(3) to start another transfer.
96
97       When  all transfers in the multi stack are done, cleanup the multi han‐
98       dle with curl_multi_cleanup(3). Be careful and  please  note  that  you
99       MUST  invoke  separate  curl_easy_cleanup(3) calls on every single easy
100       handle to clean them up properly.
101
102       If you want to re-use an easy handle that was added to the multi handle
103       for  transfer,  you  must first remove it from the multi stack and then
104       re-add it again (possibly after having altered some options at your own
105       choice).
106

MULTI_SOCKET

108       Since 7.16.0, the curl_multi_socket(3) function offers a way for appli‐
109       cations to not only avoid being forced to use  select(),  but  it  also
110       offers  a  much  more  high-performing API that will make a significant
111       difference for applications using large numbers of simultaneous connec‐
112       tions.
113
114       curl_multi_socket(3)   (and   curl_multi_socket_all(3))  is  then  used
115       instead of curl_multi_perform(3).
116

BLOCKING

118       A few areas in the code are still using blocking code, even  when  used
119       from  the multi interface. While we certainly want and intend for these
120       to get fixed in the future, you should be aware of the  following  cur‐
121       rent restrictions:
122
123        - Name resolves on non-windows unless c-ares is used
124        - GnuTLS SSL connections
125        - Active FTP connections
126        - HTTP proxy CONNECT operations
127        - SCP and SFTP connections
128        - SFTP transfers
129        - TFTP transfers
130        - file:// transfers
131
132
133
134libcurl 7.16.0                    3 Feb 2007                  libcurl-multi(3)
Impressum