curl_global_init(3) libcurl 手冊 curl_global_init(3)編程
名稱安全
curl_global_init - libcurl庫全局的初始化多線程
概要less
#include <curl/curl.h>curl
CURLcode curl_global_init(long flags);socket
描述函數
在調應libcurl庫中其餘函數以前,必須先調用這個函數對編程環境進行相應的初始化,使每一個程序調用libcurl庫函數都具備相同的效果。ui
這個按位組合選擇的整形(int)變量能夠精確告訴libcurl當下的須要的工做模式。詳細狀況,若是你不是十分熟悉總體參數的初始化,您能夠設置參數爲CURL_GLOABL_ALL。對全部的須要用到的環境進行初始化,這個函數不是安全線程,在多線程應用中,須要在主線程中調用這個函數。這個函數設置libcurl所需的環境。一般狀況,若是不顯式的調用它,第一次調用 curl_easy_init()時,curl_easy_init 會調用 curl_global_init,在單線程環境下,這不是問題。可是多線程下就不行了,由於curl_global_init不是線程安全的。在多個線 程中調用curl_easy_int,而後若是兩個線程同時發現curl_global_init尚未被調用,同時調用 curl_global_init,悲劇就發生了。這種狀況發生的機率很小,但可能性是存在的。this
看到libcurl的描述(3)的全局環境要求的細節如何使用這個函數。url
標誌
CURL_GLOBAL_ALL
初始化全部已知設置,除了後臺傳輸服務。CURL_GLOBAL_ACK_EINTR.
CURL_GLOBAL_SSL
初始化 SSL(安全套接層)
CURL_GLOBAL_WIN32
初始化Win32 因此共享函數包.
CURL_GLOBAL_NOTHING
什麼都不初始化This sets no bit.
CURL_GLOBAL_DEFAULT
一個合理的默認值。它將init SSL和Win32。如今,這個等於CURL_GLOBAL_ALL面具的功能。
CURL_GLOBAL_ACK_EINTR
這個標誌被設置時,旋度認可當鏈接或在等待數據捕獲條件。不然,旋度等待超時白白的流逝了。在7.30.0(添加)
返回值
若是這個函數返回非零,出了意外,你不能使用其餘旋度函數。
另請參閱
curl_global_init_mem(3), curl_global_cleanup(3), curl_easy_init(3), libcurl(3)
libcurl 7.12 11 May 2004 curl_global_init(3)
curl_global_init(3) libcurl Manual curl_global_init(3) NAME curl_global_init - Global libcurl initialisation SYNOPSIS #include <curl/curl.h> CURLcode curl_global_init(long flags); DESCRIPTION This function sets up the program environment that libcurl needs. Think of it as an extension of the library loader. This function must be called at least once within a program (a program is all the code that shares a memory space) before the program calls any other function in libcurl. The environment it sets up is constant for the life of the program and is the same for every program, so mul‐ tiple calls have the same effect as one call. The flags option is a bit pattern that tells libcurl exactly what fea‐ tures to init, as described below. Set the desired bits by ORing the values together. In normal operation, you must specify CURL_GLOBAL_ALL. Don't use any other value unless you are familiar with it and mean to control internal operations of libcurl. This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is run‐ ning. This doesn't just mean no other thread that is using libcurl. Because curl_global_init(3) calls functions of other libraries that are similarly thread unsafe, it could conflict with any other thread that uses these other libraries. If you are initializing libcurl from a Windows DLL you should not ini‐ tialize it from DllMain or a static initializer because Windows holds the loader lock during that time and it could cause a deadlock. See the description in libcurl(3) of global environment requirements for details of how to use this function. FLAGS CURL_GLOBAL_ALL Initialize everything possible. This sets all known bits except CURL_GLOBAL_ACK_EINTR. CURL_GLOBAL_SSL Initialize SSL CURL_GLOBAL_WIN32 Initialize the Win32 socket libraries. CURL_GLOBAL_NOTHING Initialise nothing extra. This sets no bit. CURL_GLOBAL_DEFAULT A sensible default. It will init both SSL and Win32. Right now, this equals the functionality of the CURL_GLOBAL_ALL mask. CURL_GLOBAL_ACK_EINTR When 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) RETURN VALUE If this function returns non-zero, something went wrong and you cannot use the other curl functions. SEE ALSO curl_global_init_mem(3), curl_global_cleanup(3), curl_easy_init(3) libcurl(3) libcurl 7.12 11 May 2004 curl_global_init(3)