[译]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 ...
随机推荐
- JavaScript判断页面是否已经加载完毕
做页面时经常会遇到当前页面加载完成后,执行某些初始化工作.这时候就要知道如何判断页面(包括IFRAME)已经加载完成,代码如下: < script language = "javasc ...
- 2017-10-01-afternoon
T1 一道图论好题(graph) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带 ...
- 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 ...
- ArcGIS for Android入门程序之DrawTool2.0
来自:http://blog.csdn.net/arcgis_mobile/article/details/8084763 GISpace博客<ArcGIS for Android入门程序之Dr ...
- linux工具一览
http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/sar.html
- UVa 340 Master-Mind Hints(猜数字游戏的提示)
题意 猜数字游戏 统计猜的数字有多少个数字位置正确 有多少个数字在答案中出现可是位置不对 每一个字符仅仅能匹配一次 直接匹配每位数 #include<cstdio> #includ ...
- pipenv 的使用
pipenv 的使用 学习了:https://blog.csdn.net/chroming/article/details/77104873?locationNum=4&fps=1 https ...
- Oracle index unusable和invisible的差别
摘录自11g的官方文档: UNUSABLE Specify UNUSABLE to mark the index or index partition(s) or index subpart ...
- swift编程语言基础教程 中文版
swift编程语言基础教程 中文版 http://download.csdn.net/detail/u014036026/7845491
- Num 15: NYOJ: 题目0002 : 括号配对问题 [ 栈(stack) ]
原题连接 首先要了解有关栈的一些基本知识,即: 什么是栈,栈有什么作用: 1.什么是栈: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...