[译]The multi Interface
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的更多相关文章
- [译]curl_multi_add_handle
NAMEcurl_multi_add_handle - add an easy handle to a multi session添加easy handle到multi session中 SYNOPS ...
- [译]curl_multi_perform
http://curl.haxx.se/libcurl/c/curl_multi_perform.html curl_multi_perform.3 -- man page NAMEcurl_mult ...
- [译]libcurl错误码
CURLcode Almost all "easy" interface functions return a CURLcode error code. No matter wha ...
- libcurl教程
名称 libcurl 的编程教程 目标 本文档介绍使用libcurl编程的一般原则和一些基本方法.本文主要是介绍 c 语言的调用接口,同时也可能很好的适用于其他类 c 语言的接口. 跨平台的可移植代码 ...
- linux c libcurl的简单使用(转)
curl是Linux下一个非常著名的下载库,通过这个库,可以很简单的实现文件的下载等操作.看一个简单的例子: #include <curl/curl.h> #include <std ...
- cocos2dx libcurl
转自:http://www.himigame.com/curl-libcurl/878.html 本篇介绍使用libcurl编程的一般原则和一些基本方法.本文主要是介绍 c 语言的调用接口,同时也可能 ...
- Libcurl笔记二
一: multi与easy接口的不同处The multi interface offers several abilities that the easy interface doesn't. The ...
- Libcurl笔记一
一:1,全局初始化及释放:CURLcode curl_global_init(long flags) flags: CURL_GLOBAL_ALL //初始化所有的可能的调用. CURL_GLOBAL ...
- Interfaces
阅读Java的官方Doc,总结如下. What is Interface An interface is a reference type, similar to a class, that can ...
随机推荐
- POJ3728 The merchant解题报告
Description There are N cities in a country, and there is one and only one simple path between each ...
- 18.10.7 POIN 模拟赛
期望 :80+ +90+40=210+ 实际 :30+90+0=120 链接:https://www.nowcoder.com/acm/contest/175/A来源:牛客网 时间限制:C/C++ 1 ...
- SQL PATINDEX检索
语法格式:PATINDEX ( '%pattern%' , expression ) 返回pattern字符串在表达式expression里第一次出现的位置,起始值从1开始算. pattern字符串在 ...
- Android GIS开发系列-- 入门季(14)FeatureLayer之范围查询
Android GIS开发系列-- 入门季(5),这篇文章中,我们知道如何去查找要素.现在有一个需求,查找某点5000米范围的要素,那如何来做呢?首先我们需要在地图上画个5000米半径的圆,然后根据Q ...
- [React] Validate Compound Component Context Consumers
If someone uses one of our compound components outside the React.createContext <ToggleContext.Pro ...
- C# .NET using ManagementObjectSearcher提示缺少引用怎么办
在下图中,即使引用了System.Management还是会出现报错 其实只要添加这条引用就可以了
- java实现floyd统计天津地铁的网站距离
一:说明 (1)使用floyd实现各个网站的计算记录和路径 (2)网站获取和初始距离依据外部文件得到 (3)结果以外部文件的形式存储 (4)网站间转乘,觉得初始值也为1 (5)代码凝视比較具体,如有疑 ...
- 华为OJ2011-最长公共子串
一.题目描述 描述: 计算两个字符串的最大公共子串(Longest Common Substring)的长度,字符区分大小写. 输入: 输入两个字符串 输出: 输出一个整数 样例输入: asdfas ...
- ubuntu下apache+mysql+php+mysql等之webserver搭建
相信非常多人跟我一样,想搭建一个自己的webserver.网上资料非常多.可是因为版本号的区别,总是存在依照一个教程来做无法全然实现的问题.近期我也折腾了好几天,google不能用,仅仅能百度,真想说 ...
- c++运算符重载以及一些基本概念
c++primer第四版435 1.赋值( = ), 下标( [ ] ) ,调用 ( ( ) ), 成员訪问箭头 (->)等操作符必须定义为成员,定义为非成员时,编译器报错 2. 像赋值一样 ...