The multi Interface
multi接口

The easy interface as described in detail in this document is a synchronous interface that transfers one file at a time and doesn't return until it is done.
easy接口是同步的,调用同步接口传输文件,需要等到传输完毕函数才会返回。

The multi interface, on the other hand, allows your program to transfer multiple files in both directions at the same time, without forcing you to use multiple threads. The name might make it seem that the multi interface is 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 that multi-threaded programs can perform. It allows many of the benefits of multi-threaded transfers without the complexity of managing and synchronizing many threads.
multi接口,允许你的程序同时向不同目标传输文件,而不需要使用多线程。
multi这个名字让他看起来像是多线程的程序,但是实际上不是。
multi可以在单线程、多线程程序中执行。

To complicate matters somewhat more, there are even two 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 man page for details on the multi_socket event based API, this description here is for the select() oriented one.
比较麻烦的是,有2个版本的multi接口。
第一个被称为multi_socket,使用的是select()机制。

To use this interface, you are better off if you first understand the basics of how to use the easy interface. The multi interface is simply a way to make multiple transfers at the same time by adding up multiple easy handles into a "multi stack".
要使用这个接口,最好先了解如何使用easy接口。
Multi接口同时传输文件是通过把多个easy_curl的句柄添加到“multi stack”中。

You create the easy handles you want, one for each concurrent transfer, and you set all the options just like you learned above, and then you create a multi handle with curl_multi_init and add all those easy handles to that multi handle with curl_multi_add_handle.
创建easy句柄后,作为并发传输的句柄之一,并设置你所需要的属性,
然后使用curl_multi_init函数创建一个multi句柄,使用curl_multi_add_handle函数添加所有easy句柄到multi句柄中。

When you've added the handles you have for the moment (you can still add new ones at any time), you start the transfers by calling curl_multi_perform.
你可以随时添加easy句柄到multi句柄中,然后使用curl_multi_perfrorm函数执行传输。

curl_multi_perform is asynchronous. It will only perform what can be done now and then return back control to your program. It is designed to never block. You need to keep calling the function until all transfers are completed.
curl_multi_perform异步的,这个函数只执行当前能执行的操作,等到全部执行完毕再回调通知程序。
你需要保持这个函数的调用,直到所有传输完成。

The best usage of this interface is when you do a select() on all possible file descriptors or sockets to know when to call libcurl again. This also makes it easy for you to wait and respond to actions on your own application's sockets/handles. You figure out what to select() for by using curl_multi_fdset, that fills in a set of fd_set variables for you with the particular file descriptors libcurl uses for the moment.
这个接口最好的用法是:你select()所有文件描述符或者sokect,来查看libcurl是否通知了。
这也使得你的程序在等待、回复时更简单。
使用curl_multi_fdset函数来找出应该select()什么,填入参数为你当前使用的libcurl文件描述符的fd_set对。

When you then call select(), it'll return when one of the file handles signal action and you then call curl_multi_perform to allow libcurl to do what it wants to do. Take note that libcurl does also feature some time-out code so we advise you to never use very long timeouts on select() before you call curl_multi_perform again. curl_multi_timeout is provided to help you get a suitable timeout period.
当调用select()时候,当检测到文件句柄有信号会返回,
你可以调用curl_multi_perform来允许libcurl执行。
需要注意的是libcurl会超时,所以建议绝对不要在调用curl_multi_perform之前,设置长时间的select()设置长时间的超时。
curl_multi_timeout函数用于帮你获取一个合适的超时时间。

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.
其他注意点:在调用select()前,使用curl_multi_fdset,防止当前文件描述符对被其他libcurl函数改变。

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 individual easy handles. Remember that easy handles should be curl_easy_cleanuped.
如果你想停止multi stack中的easy handle,你可以使用curl_mult_remove_handle函数来移除一个easy handle。
之后记得要使用curl_easy_cleanuped。

When a transfer within the multi stack has finished, the counter of running transfers (as filled in by curl_multi_perform) will decrease. When the number reaches zero, all transfers are done.
当multi stack中的一个传输完成,运行中的传输计数(curl_multi_perform函数的参数)会减一。
当计数为0,表示所有传输完成。

curl_multi_info_read can be used to get information about completed transfers. It then returns the CURLcode for each easy transfer, to allow you to figure out success on each individual transfer.
curl_multi_info_read用于获取已完成的传输信息,这个函数会返回每个easy handle传输的CURLcode,
CURLcode用于查看传输结果

[译]The multi Interface的更多相关文章

  1. [译]curl_multi_add_handle

    NAMEcurl_multi_add_handle - add an easy handle to a multi session添加easy handle到multi session中 SYNOPS ...

  2. [译]curl_multi_perform

    http://curl.haxx.se/libcurl/c/curl_multi_perform.html curl_multi_perform.3 -- man page NAMEcurl_mult ...

  3. [译]libcurl错误码

    CURLcode Almost all "easy" interface functions return a CURLcode error code. No matter wha ...

  4. libcurl教程

    名称 libcurl 的编程教程 目标 本文档介绍使用libcurl编程的一般原则和一些基本方法.本文主要是介绍 c 语言的调用接口,同时也可能很好的适用于其他类 c 语言的接口. 跨平台的可移植代码 ...

  5. linux c libcurl的简单使用(转)

    curl是Linux下一个非常著名的下载库,通过这个库,可以很简单的实现文件的下载等操作.看一个简单的例子: #include <curl/curl.h> #include <std ...

  6. cocos2dx libcurl

    转自:http://www.himigame.com/curl-libcurl/878.html 本篇介绍使用libcurl编程的一般原则和一些基本方法.本文主要是介绍 c 语言的调用接口,同时也可能 ...

  7. Libcurl笔记二

    一: multi与easy接口的不同处The multi interface offers several abilities that the easy interface doesn't. The ...

  8. Libcurl笔记一

    一:1,全局初始化及释放:CURLcode curl_global_init(long flags) flags: CURL_GLOBAL_ALL //初始化所有的可能的调用. CURL_GLOBAL ...

  9. Interfaces

    阅读Java的官方Doc,总结如下. What is Interface An interface is a reference type, similar to a class, that can ...

随机推荐

  1. Our Journey of Dalian Ends 乌鲁木齐网络赛 最小费用最大流

    Life is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpecte ...

  2. UVA 1025_A Spy in the Metro

    [题意](小紫书)一个人从站台1出发,乘车要在时刻T到达站台n,为使在站台等车时间最短,她可以选择乘坐两个方向的列车,并在客车停靠站的时候换车. [分析]每次停站下车时,她都有三种选择,1.原地不动 ...

  3. Why It is so hard to explain or show some thing

    Why it is hard to explain something or learn something? For example, when I first know the hadoop, I ...

  4. laravel toggle方法

    toggle方法主要用于多对多关系中,attach detach 比如点赞 收藏 1.user表 2.post表 title content 3.中间表 favoriate user_id post_ ...

  5. hadoop 文件操作

    Create a directory in HDFS - mkdir The hadoop mkdir command is for creating directories in the hdfs. ...

  6. 安卓数据传递之---putextra与putextras

    一.public Intent putExtra (String name, double[] value) 设置方法 intent.putExtra("aaa", "b ...

  7. Loadrunner&Jemeter进行手机APP压力测试

    一.loadrunner通过代理录制app脚本 随着手机APP的广泛应用,手机应用的使用已占据了大量的市场份额,尤其是优秀的手机APP,动辄用户过千万过亿,对于如此庞大的用户量,我们在开发APP时,也 ...

  8. 图像处理之基础---基于opencv的灰度图像微分

    argv分别为,可执行文件名.读入的原始图像.输出原始图像的灰度值.输出原始图像灰度值沿x轴方向的一阶微分.输出原始图像灰度值沿x轴方向的二阶微分. #include #include #includ ...

  9. CPU卡的读写【转】

    本文转载自:http://blog.csdn.net/logaa/article/details/7465226 一般来说,对存储卡和逻辑加密卡操作,使用接触式IC卡通用读写器:对CPU卡使用CPU卡 ...

  10. JFreeChart自我总结

    想飞就别怕摔 大爷的并TM骂人 JFreeChart自我总结 1.饼图.柱状图.折线图生成的工具类   1 package com.text.util;  2   3 import java.awt. ...