The Multi Interface
Multi interface
The easy interface as described in detail in this document are a synchronous interface that transfers one file at a time a D doesn ' t return until it was done.
The easy interface is synchronous and calls the synchronization interface to transfer the file, which needs to wait until the transfer is complete before the function returns.
The multi interface, on the other hand, allows your program to transfer multiple files in both directions at the same time , without forcing you multiple threads. The name might make it seem the multi interface are for multi-threaded programs, but the truth is almost the reverse. The multi interface allows a single-threaded application to perform the same kinds of multiple, simultaneous transfers tha T multi-threaded programs can perform. It allows many of the benefits of multi-threaded transfers without the complexity of managing and synchronizing many Threa Ds.
The multi interface allows your program to transfer files to different targets at the same time, without the need to use multithreading.
Multi's name makes him look like a multithreaded program, but it's not actually.
Multi can be executed in single-threaded, multithreaded programs.
To complicate matters somewhat more, there is even both versions of the multi interface. The event based one, also called Multi_socket and the "normal one" designed for using with select (). See the LIBCURL-MULTI.3 Mans page for details on the Multi_socket event based API, this description here's for the Select ( ) oriented one.
The trouble is that there are 2 versions of the multi interface.
The first is called Multi_socket, which uses the select () mechanism.
To use this interface, you is better off if you first understand the basics of the and the Easy interface. The multi interface is simply a-to-make multiple transfers at the same time by adding up multiple easy handles into a "Multi Stack".
To use this interface, it is best to first understand how to use the easy interface.
The multi interface transfers files simultaneously by adding multiple Easy_curl handles to the multi stack.
You create the ' easy handles ' want, one for each concurrent transfer, and your set all the options just as you learned Above, and then you create a multi handle with curl_multi_init and add all those easy handles to the multi handle with CU Rl_multi_add_handle.
After you create the easy handle, as one of the handles for the concurrent transfer, and set the properties that you want,
Then use the Curl_multi_init function to create a multi handle, and use the Curl_multi_add_handle function to add all the easy handles to the multi handle.
When you've added the handles you had for the moment (you can still add new ones at any time), you start the transfers by Calling Curl_multi_perform.
You can add easy handles to the multi handle at any time, and then use the Curl_multi_perfrorm function to perform the transfer.
Curl_multi_perform is asynchronous. It would only perform what can is done now and then return the back control to your program. It's designed to never block. You need to keep calling the function until all transfers is completed.
Curl_multi_perform asynchronous, this function only performs the operation that is currently possible, waits until all is done and then callbacks the notifier.
You need to keep this function called until all the transfers are complete.
The best usage of this interface was when you did a select () on all possible file descriptors or sockets to know when to Call Libcurl again. This is also makes it easy-to-wait and respond-to-actions on your own application ' s sockets/handles. You figure out which to select () for by using Curl_multi_fdset, which fills in a set of Fd_set variables for the PA Rticular file descriptors Libcurl uses for the moment. The best use of the
interface is: you select () all file descriptors or sokect to see if Libcurl is notified.
This also makes your program easier to wait and reply to. The
uses the Curl_multi_fdset function to find out what should be a select () and fill in the Fd_set pair of parameters for the Libcurl file descriptor you are currently using.
When I call select (), it's return when one of the the file handles signal action and your then call Curl_multi_perform To allow the libcurl to does what the IT wants to do. Take note this Libcurl does also feature some time-out code so we advise the never use very a long timeouts on select () b Efore call Curl_multi_perform again. Curl_multi_timeout is provided to help you get a suitable timeout period.
When a select () is called, when a file handle is detected, a signal is returned,
You can call Curl_multi_perform to allow Libcurl to execute.
It is important to note that Libcurl times out, so it is recommended that you never set long time-outs before calling Curl_multi_perform, setting long Select ().
The Curl_multi_timeout function is used to help you get a suitable time-out.
Another precaution you should use:always call Curl_multi_fdset immediately before the Select () call since the current set of file descriptors may change in any curl function invoke.
Other points of note: before calling select (), use Curl_multi_fdset to prevent the current file descriptor pair from being changed by other Libcurl functions.
If you want to stop the transfer of one of the "easy handles" in the stack, you can use Curl_multi_remove_handle to remove I Ndividual Easy handles. Remember that easy handles should is curl_easy_cleanuped.
If you want to stop the easy handle in the multi stack, you can use the Curl_mult_remove_handle function to remove an easily handle.
Then remember to use curl_easy_cleanuped.
When a transfer within the multi stack had finished, the counter of running transfers (as filled in by Curl_multi_perform) would decrease. When the number reaches zero, all transfers is done.
When a transfer in the multi stack is complete, the running transfer count (the parameters of the Curl_multi_perform function) is reduced by one.
When the count is 0, all transmissions are complete.
Curl_multi_info_read can used to get information about completed transfers. It then returns the Curlcode-for-each-easy transfer, and to-allow-you-to-figure out success on each individual transfer.
The curl_multi_info_read is used to obtain the completed transfer information, which returns the Curlcode of each easy handle transmission.
Curlcode for viewing transfer results
Translation The Multi Interface