curl_easy_init(3) libcurl 手冊 curl_easy_init(3)
名字
curl_easy_init - 開始一個簡單的libcurl會話
梗概
#include <curl/curl.h>
CURL *curl_easy_init( );
描述
此函數必須是調用的第一個函數,它返回一個curl類型的文件描述指針,你必須使用作為輸入到其他功能之前使用。這個調用必須有一個相應的調用curl_easy_cleanup(3)當操作完成。
如果你沒有調用call的curl_global_init(3)函數, curl_easy_init(3)會自動幫你完成調用.這在多線程中會出現致命的問題,因為curl_global_init(3)不是線程安全的,它可能會因為沒有相應的清理導致資源的問題。
建議你不要通過調用而得到curl_global_init(3)體現。詳細介紹了如何使用這個功能請看到libcurl的描述(3)全局環境的要求。
返回值
如果這個函數的返回值為NULL,你將不能使用curl中的任何函數。
范例
1 CURL *curl = curl_easy_init(); 2 if(curl) { 3 CURLcode res; 4 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); 5 res = curl_easy_perform(curl); 6 curl_easy_cleanup(curl); 7 }
請參閱
curl_easy_cleanup(3), curl_global_init(3), curl_easy_reset(3), curl_easy_perform(3)
libcurl 7.8.1 4 March 2002 curl_easy_init(3)
1 curl_easy_init(3) libcurl Manual curl_easy_init(3) 2 3 NAME 4 curl_easy_init - Start a libcurl easy session 5 6 SYNOPSIS 7 #include <curl/curl.h> 8 9 CURL *curl_easy_init( ); 10 11 DESCRIPTION 12 This function must be the first function to call, and it returns a CURL easy handle that you must use as input to other functions in the 13 easy interface. This call MUST have a corresponding call to curl_easy_cleanup(3) when the operation is complete. 14 15 If you did not already call curl_global_init(3), curl_easy_init(3) does it automatically. This may be lethal in multi-threaded cases, 16 since curl_global_init(3) is not thread-safe, and it may result in resource problems because there is no corresponding cleanup. 17 18 You are strongly advised to not allow this automatic behaviour, by calling curl_global_init(3) yourself properly. See the description in 19 libcurl(3) of global environment requirements for details of how to use this function. 20 21 RETURN VALUE 22 If this function returns NULL, something went wrong and you cannot use the other curl functions. 23 24 EXAMPLE 25 CURL *curl = curl_easy_init(); 26 if(curl) { 27 CURLcode res; 28 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); 29 res = curl_easy_perform(curl); 30 curl_easy_cleanup(curl); 31 } 32 33 SEE ALSO 34 curl_easy_cleanup(3), curl_global_init(3), curl_easy_reset(3), curl_easy_perform(3) 35 36 libcurl 7.8.1 4 March 2002 curl_easy_init(3)