第二人生的源码分析(六十二)类Easy实现多协议文件传送
2008-05-14 20:42
791 查看
从上一节里可以看到,在类LLCurl声明里主要声明嵌套类Easy,最后通过嵌套类Easy来实现libcurl功能,下面就来仔细地分析它。它的类声明如下:
#001 class LLCurl::Easy
#002 {
#003 LOG_CLASS(Easy);
#004
#005 private:
#006 Easy();
#007
#008 public:
用工厂模式来创建类实例。
#009 static Easy* getEasy();
#010 ~Easy();
#011
返回当前libcurl库的句柄。
#012 CURL* getCurlHandle() const { return mCurlEasyHandle; }
#013
设置错误缓冲区。
#014 void setErrorBuffer();
设置授权认证。
#015 void setCA();
#016
调用库的函数curl_easy_setopt。
#017 void setopt(CURLoption option, S32 value);
#018 // These assume the setter does not free value!
#019 void setopt(CURLoption option, void* value);
#020 void setopt(CURLoption option, char* value);
#021 // Copies the string so that it is gauranteed to stick around
#022 void setoptString(CURLoption option, const std::string& value);
#023
调用库函数curl_slist_append来添加到列表头里面。
#024 void slist_append(const char* str);
设置HTTP协议头数据。
#025 void setHeaders();
#026
报告错误信息。
#027 U32 report(CURLcode);
获取传送信息。
#028 void getTransferInfo(LLCurl::TransferInfo* info);
#029
在使用库下载数据前的设置。
#030 void prepRequest(const std::string& url, ResponderPtr, bool post = false);
#031
#032 const char* getErrorBuffer();
#033
获取输入流对象。
#034 std::stringstream& getInput() { return mInput; }
获取输出协议头流对象。
#035 std::stringstream& getHeaderOutput() { return mHeaderOutput; }
获取输出流对象。
#036 LLIOPipe::buffer_ptr_t& getOutput() { return mOutput; }
#037 const LLChannelDescriptors& getChannels() { return mChannels; }
#038
清空所有流对象和一些状态。
#039 void resetState();
#040
#041 private:
#042 CURL* mCurlEasyHandle;
#043 struct curl_slist* mHeaders;
#044
#045 std::stringstream mRequest;
#046 LLChannelDescriptors mChannels;
#047 LLIOPipe::buffer_ptr_t mOutput;
#048 std::stringstream mInput;
#049 std::stringstream mHeaderOutput;
#050 char mErrorBuffer[CURL_ERROR_SIZE];
#051
#052 // Note: char*'s not strings since we pass pointers to curl
#053 std::vector<char*> mStrings;
#054
#055 ResponderPtr mResponder;
#056 };
上面的类Easy封装了函数curl_easy_init来初始化一个协议实例,函数curl_easy_cleanup来删除相应的实例,函数curl_easy_reset来复位相关状态,通过函数curl_easy_getinfo来获取信息。最后通过函数curl_easy_setopt来设置不同的参数,这样才实现libcurl库的功能调用。
#001 class LLCurl::Easy
#002 {
#003 LOG_CLASS(Easy);
#004
#005 private:
#006 Easy();
#007
#008 public:
用工厂模式来创建类实例。
#009 static Easy* getEasy();
#010 ~Easy();
#011
返回当前libcurl库的句柄。
#012 CURL* getCurlHandle() const { return mCurlEasyHandle; }
#013
设置错误缓冲区。
#014 void setErrorBuffer();
设置授权认证。
#015 void setCA();
#016
调用库的函数curl_easy_setopt。
#017 void setopt(CURLoption option, S32 value);
#018 // These assume the setter does not free value!
#019 void setopt(CURLoption option, void* value);
#020 void setopt(CURLoption option, char* value);
#021 // Copies the string so that it is gauranteed to stick around
#022 void setoptString(CURLoption option, const std::string& value);
#023
调用库函数curl_slist_append来添加到列表头里面。
#024 void slist_append(const char* str);
设置HTTP协议头数据。
#025 void setHeaders();
#026
报告错误信息。
#027 U32 report(CURLcode);
获取传送信息。
#028 void getTransferInfo(LLCurl::TransferInfo* info);
#029
在使用库下载数据前的设置。
#030 void prepRequest(const std::string& url, ResponderPtr, bool post = false);
#031
#032 const char* getErrorBuffer();
#033
获取输入流对象。
#034 std::stringstream& getInput() { return mInput; }
获取输出协议头流对象。
#035 std::stringstream& getHeaderOutput() { return mHeaderOutput; }
获取输出流对象。
#036 LLIOPipe::buffer_ptr_t& getOutput() { return mOutput; }
#037 const LLChannelDescriptors& getChannels() { return mChannels; }
#038
清空所有流对象和一些状态。
#039 void resetState();
#040
#041 private:
#042 CURL* mCurlEasyHandle;
#043 struct curl_slist* mHeaders;
#044
#045 std::stringstream mRequest;
#046 LLChannelDescriptors mChannels;
#047 LLIOPipe::buffer_ptr_t mOutput;
#048 std::stringstream mInput;
#049 std::stringstream mHeaderOutput;
#050 char mErrorBuffer[CURL_ERROR_SIZE];
#051
#052 // Note: char*'s not strings since we pass pointers to curl
#053 std::vector<char*> mStrings;
#054
#055 ResponderPtr mResponder;
#056 };
上面的类Easy封装了函数curl_easy_init来初始化一个协议实例,函数curl_easy_cleanup来删除相应的实例,函数curl_easy_reset来复位相关状态,通过函数curl_easy_getinfo来获取信息。最后通过函数curl_easy_setopt来设置不同的参数,这样才实现libcurl库的功能调用。
相关文章推荐
- 蔡军生先生第二人生的源码分析(六十二)类Easy实现多协议文件传送
- 第二人生的源码分析(六十二)类Easy实现多协议文件传送
- 第二人生的源码分析(六十二)类Easy实现多协议文件传送
- 第二人生的源码分析(六十)多协议文件传送库libcurl的介绍
- 蔡军生先生第二人生的源码分析(六十)多协议文件传送库libcurl的介绍
- 第二人生的源码分析(六十)多协议文件传送库libcurl的介绍
- 第二人生的源码分析(六十)多协议文件传送库libcurl的介绍
- 第二人生的源码分析(5)类Log的实现
- 第二人生的源码分析(10)登录授权的实现过程
- 第二人生的源码分析(八十五)LLView实现OpenGL窗口显示
- 第二人生的源码分析(九十二)LLLineEditor实现编辑框
- 第二人生的源码分析(十七)人物Mesh数据显示的实现
- 第二人生的源码分析(九十三)LLComboBox类实现组合框
- 第二人生的源码分析(三十五)分析消息模板文件
- 第二人生的源码分析(十八)人物纹理显示的实现
- 第二人生的源码分析(九十四)LLTextBox类实现文本显示
- 蔡军生先生第二人生的源码分析(五十九)字体类LLFont的实现
- 蔡军生先生第二人生的源码分析(六十七)LLXMLNode使用Expat库打开文件
- 第二人生的源码分析(六十三)类Multi实现多请求
- 第二人生的源码分析(六十九)使用LLXmlTree类来分析XML配置文件