Cocos2d-x中libcurl库的使用(1)查看库的版本信息

前端之家收集整理的这篇文章主要介绍了Cocos2d-x中libcurl库的使用(1)查看库的版本信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用如下代码,可检测Cocos2d-x中使用的libcurl库的版本信息

  1. #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
  2. #include "../cocos2d/external/curl/include/ios/curl/curl.h"
  3. #endif
  4.  
  5. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  6. #include "../cocos2d/external/curl/include/android/curl/curl.h"
  7. #endif
  8.  
  9. int getVersion()
  10. {
  11. CURLcode return_code;
  12. return_code = curl_global_init(CURL_GLOBAL_ALL);
  13. if(CURLE_OK != return_code)
  14. {
  15. log("init libcurl Failed");
  16. return -1;
  17. }
  18. log("curl_version=%s",curl_version());
  19. curl_version_info_data *p = curl_version_info(CURLVERSION_NOW);
  20. log("curl_version_info_data = %u",p->version_num);
  21. curl_global_cleanup();
  22. return 0;
  23. }

1、curl_global_init的参数flag

CURL_GLOBAL_ALLInitialize everything possible. This sets all known bits exceptCURL_GLOBAL_ACK_EINTR.

CURL_GLOBAL_SSLInitialize SSL

CURL_GLOBAL_WIN32Initialize the Win32 socket libraries.

CURL_GLOBAL_NOTHINGInitialise nothing extra. This sets no bit.

CURL_GLOBAL_DEFAULTA sensible default. It will init both SSL and Win32. Right now,this equals the functionality of theCURL_GLOBAL_ALLmask.

CURL_GLOBAL_ACK_EINTRWhen this flag is set,curl will acknowledge EINTR condition when connecting or when waiting for data. Otherwise,curl waits until full timeout elapses. (Added in 7.30.0)

2、curl_version_info_data结构体

  1. typedef struct {
  2. CURLversion age; /* age of the returned struct */
  3. const char *version; /* LIBCURL_VERSION */
  4. unsigned int version_num; /* LIBCURL_VERSION_NUM */
  5. const char *host; /* OS/host/cpu/machine when configured */
  6. int features; /* bitmask,see defines below */
  7. const char *ssl_version; /* human readable string */
  8. long ssl_version_num; /* not used anymore,always 0 */
  9. const char *libz_version; /* human readable string */
  10. /* protocols is terminated by an entry with a NULL protoname */
  11. const char * const *protocols;
  12.  
  13. /* The fields below this were added in CURLVERSION_SECOND */
  14. const char *ares;
  15. int ares_num;
  16.  
  17. /* This field was added in CURLVERSION_THIRD */
  18. const char *libidn;
  19.  
  20. /* These field were added in CURLVERSION_FOURTH */
  21.  
  22. /* Same as '_libiconv_version' if built with HAVE_ICONV */
  23. int iconv_ver_num;
  24.  
  25. const char *libssh_version; /* human readable string */
  26.  
  27. } curl_version_info_data;
3、curl_global_init初始化libcurl,CURL_GLOBAL_ALL会使libcurl初始化所有的子模块和一些默认的选项,这个一个比较好的默认值

4、curl_global_cleanup,释放资源,curl_global_init和curl_global_cleanup只能被调用一次。

猜你在找的Cocos2d-x相关文章