curl_global_init.md (3913B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: curl_global_init 5 Section: 3 6 Source: libcurl 7 See-also: 8 - curl_easy_init (3) 9 - curl_global_cleanup (3) 10 - curl_global_init_mem (3) 11 - curl_global_sslset (3) 12 - curl_global_trace (3) 13 - libcurl (3) 14 Protocol: 15 - All 16 Added-in: 7.8 17 --- 18 19 # NAME 20 21 curl_global_init - global libcurl initialization 22 23 # SYNOPSIS 24 25 ~~~c 26 #include <curl/curl.h> 27 28 CURLcode curl_global_init(long flags); 29 ~~~ 30 31 # DESCRIPTION 32 33 This function sets up the program environment that libcurl needs. Think of it 34 as an extension of the library loader. 35 36 This function must be called at least once within a program (a program is all 37 the code that shares a memory space) before the program calls any other 38 function in libcurl. The environment it sets up is constant for the life of 39 the program and is the same for every program, so multiple calls have the same 40 effect as one call. 41 42 The flags option is a bit pattern that tells libcurl exactly what features to 43 init, as described below. Set the desired bits by ORing the values together. 44 In normal operation, you must specify CURL_GLOBAL_ALL. Do not use any other 45 value unless you are familiar with it and mean to control internal operations 46 of libcurl. 47 48 This function is thread-safe on most platforms. Then curl_version_info(3) has 49 the `threadsafe` feature set (added in 7.84.0). 50 51 If this is not thread-safe (the bit mentioned above is not set), you must not 52 call this function when any other thread in the program (i.e. a thread sharing 53 the same memory) is running. This does not just mean no other thread that is 54 using libcurl. Because curl_global_init(3) calls functions of other libraries 55 that are similarly thread unsafe, it could conflict with any other thread that 56 uses these other libraries. 57 58 If you are initializing libcurl from a Windows DLL you should not initialize 59 it from *DllMain* or a static initializer because Windows holds the loader 60 lock during that time and it could cause a deadlock. 61 62 See the description in libcurl(3) of global environment requirements for 63 details of how to use this function. 64 65 # FLAGS 66 67 ## CURL_GLOBAL_ALL 68 69 Initialize everything possible. This sets all known bits except 70 **CURL_GLOBAL_ACK_EINTR**. 71 72 ## CURL_GLOBAL_SSL 73 74 (This flag's presence or absence serves no meaning since 7.57.0. The 75 description below is for older libcurl versions.) 76 77 Initialize SSL. 78 79 The implication here is that if this bit is not set, the initialization of the 80 SSL layer needs to be done by the application or at least outside of 81 libcurl. The exact procedure how to do SSL initialization depends on the TLS 82 backend libcurl uses. 83 84 Doing TLS based transfers without having the TLS layer initialized may lead to 85 unexpected behaviors. 86 87 ## CURL_GLOBAL_WIN32 88 89 Initialize the Win32 socket libraries. 90 91 The implication here is that if this bit is not set, the initialization of 92 Winsock has to be done by the application or you risk getting undefined 93 behaviors. This option exists for when the initialization is handled outside 94 of libcurl so there is no need for libcurl to do it again. 95 96 ## CURL_GLOBAL_NOTHING 97 98 Initialize nothing extra. This sets no bit. 99 100 ## CURL_GLOBAL_DEFAULT 101 102 A sensible default. It initializes both SSL and Win32. Right now, this equals 103 the functionality of the **CURL_GLOBAL_ALL** mask. 104 105 ## CURL_GLOBAL_ACK_EINTR 106 107 This bit has no point since 7.69.0 but its behavior is instead the default. 108 109 Before 7.69.0: when this flag is set, curl acknowledges EINTR condition when 110 connecting or when waiting for data. Otherwise, curl waits until full timeout 111 elapses. (Added in 7.30.0) 112 113 # %PROTOCOLS% 114 115 # EXAMPLE 116 117 ~~~c 118 int main(void) 119 { 120 curl_global_init(CURL_GLOBAL_DEFAULT); 121 122 /* use libcurl, then before exiting... */ 123 124 curl_global_cleanup(); 125 } 126 ~~~ 127 128 # %AVAILABILITY% 129 130 # RETURN VALUE 131 132 If this function returns non-zero, something went wrong and you cannot use the 133 other curl functions.