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