從上一節里可以看到,在類
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庫的功能調用。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
