Install curl-7.19.5.tar.bz2
[msysgit.git] / mingw / share / man / man3 / libcurl.3
blob90465f71e9d6f2d438088f37d660e465d86e5297
1 .\" $Id: libcurl.3,v 1.14 2008-12-22 13:07:14 bagder Exp $
2 .\"
3 .TH libcurl 3 "19 March 2002" "libcurl 7.9.6" "libcurl overview"
4 .SH NAME
5 libcurl \- client-side URL transfers
6 .SH DESCRIPTION
7 This is a short overview on how to use libcurl in your C programs. There are
8 specific man pages for each function mentioned in here. There are also the
9 \fIlibcurl-easy(3)\fP man page, the \fIlibcurl-multi(3)\fP man page, the
10 \fIlibcurl-share(3)\fP man page and the \fIlibcurl-tutorial(3)\fP man page for
11 in-depth understanding on how to program with libcurl.
13 There are more than thirty custom bindings available that bring libcurl access
14 to your favourite language. Look elsewhere for documentation on those.
16 libcurl has a global constant environment that you must set up and
17 maintain while using libcurl.  This essentially means you call
18 \fIcurl_global_init(3)\fP at the start of your program and
19 \fIcurl_global_cleanup(3)\fP at the end.  See GLOBAL CONSTANTS below
20 for details.
22 To transfer files, you always set up an "easy handle" using
23 \fIcurl_easy_init(3)\fP, but when you want the file(s) transferred you have
24 the option of using the "easy" interface, or the "multi" interface.
26 The easy interface is a synchronous interface with which you call
27 \fIcurl_easy_perform(3)\fP and let it perform the transfer. When it is
28 completed, the function returns and you can continue. More details are found in
29 the \fIlibcurl-easy(3)\fP man page.
31 The multi interface on the other hand is an asynchronous interface, that you
32 call and that performs only a little piece of the transfer on each invoke. It
33 is perfect if you want to do things while the transfer is in progress, or
34 similar. The multi interface allows you to select() on libcurl action, and
35 even to easily download multiple files simultaneously using a single thread. See further details in the \fIlibcurl-multi(3)\fP man page.
37 You can have multiple easy handles share certain data, even if they are used
38 in different threads. This magic is setup using the share interface, as
39 described in the \fIlibcurl-share(3)\fP man page.
41 There is also a series of other helpful functions to use, including these:
42 .RS
43 .IP curl_version_info()
44 gets detailed libcurl (and other used libraries) version info
45 .IP curl_getdate()
46 converts a date string to time_t
47 .IP curl_easy_getinfo()
48 get information about a performed transfer
49 .IP curl_formadd()
50 helps building an HTTP form POST
51 .IP curl_formfree()
52 free a list built with \fIcurl_formadd(3)\fP
53 .IP curl_slist_append()
54 builds a linked list
55 .IP curl_slist_free_all()
56 frees a whole curl_slist
57 .RE
59 .SH "LINKING WITH LIBCURL"
60 On unix-like machines, there's a tool named curl-config that gets installed
61 with the rest of the curl stuff when 'make install' is performed.
63 curl-config is added to make it easier for applications to link with libcurl
64 and developers to learn about libcurl and how to use it.
66 Run 'curl-config --libs' to get the (additional) linker options you need to
67 link with the particular version of libcurl you've installed. See the
68 \fIcurl-config(1)\fP man page for further details.
70 Unix-like operating system that ship libcurl as part of their distributions
71 often don't provide the curl-config tool, but simply install the library and
72 headers in the common path for this purpose.
74 .SH "LIBCURL SYMBOL NAMES"
75 All public functions in the libcurl interface are prefixed with 'curl_' (with
76 a lowercase c). You can find other functions in the library source code, but
77 other prefixes indicate that the functions are private and may change without
78 further notice in the next release.
80 Only use documented functions and functionality!
81 .SH "PORTABILITY"
82 libcurl works
83 .B exactly
84 the same, on any of the platforms it compiles and builds on.
85 .SH "THREADS"
86 Never ever call curl-functions simultaneously using the same handle from
87 several threads. libcurl is thread-safe and can be used in any number of
88 threads, but you must use separate curl handles if you want to use libcurl in
89 more than one thread simultaneously.
91 The global environment functions are not thread-safe.  See GLOBAL CONSTANTS
92 below for details.
94 .SH "PERSISTENT CONNECTIONS"
95 Persistent connections means that libcurl can re-use the same connection for
96 several transfers, if the conditions are right.
98 libcurl will \fBalways\fP attempt to use persistent connections. Whenever you
99 use \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP, libcurl will
100 attempt to use an existing connection to do the transfer, and if none exists
101 it'll open a new one that will be subject for re-use on a possible following
102 call to \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP.
104 To allow libcurl to take full advantage of persistent connections, you should
105 do as many of your file transfers as possible using the same curl handle. When
106 you call \fIcurl_easy_cleanup(3)\fP, all the possibly open connections held by
107 libcurl will be closed and forgotten.
109 Note that the options set with \fIcurl_easy_setopt(3)\fP will be used on
110 every repeated \fIcurl_easy_perform(3)\fP call.
112 .SH "GLOBAL CONSTANTS"
113 There are a variety of constants that libcurl uses, mainly through its
114 internal use of other libraries, which are too complicated for the
115 library loader to set up.  Therefore, a program must call a library
116 function after the program is loaded and running to finish setting up
117 the library code.  For example, when libcurl is built for SSL
118 capability via the GNU TLS library, there is an elaborate tree inside
119 that library that describes the SSL protocol.
121 \fIcurl_global_init()\fP is the function that you must call.  This may
122 allocate resources (e.g. the memory for the GNU TLS tree mentioned
123 above), so the companion function \fIcurl_global_cleanup()\fP releases
124 them.
126 The basic rule for constructing a program that uses libcurl is this:
127 Call \fIcurl_global_init()\fP, with a \fICURL_GLOBAL_ALL\fP argument,
128 immediately after the program starts, while it is still only one
129 thread and before it uses libcurl at all.  Call
130 \fIcurl_global_cleanup()\fP immediately before the program exits, when
131 the program is again only one thread and after its last use of
132 libcurl.
134 You can call both of these multiple times, as long as all calls meet
135 these requirements and the number of calls to each is the same.
137 It isn't actually required that the functions be called at the beginning
138 and end of the program -- that's just usually the easiest way to do it.
139 It \fIis\fP required that the functions be called when no other thread
140 in the program is running.
142 These global constant functions are \fInot thread safe\fP, so you must
143 not call them when any other thread in the program is running.  It
144 isn't good enough that no other thread is using libcurl at the time,
145 because these functions internally call similar functions of other
146 libraries, and those functions are similarly thread-unsafe.  You can't
147 generally know what these libraries are, or whether other threads are
148 using them.
150 The global constant situation merits special consideration when the
151 code you are writing to use libcurl is not the main program, but rather
152 a modular piece of a program, e.g. another library.  As a module,
153 your code doesn't know about other parts of the program -- it doesn't
154 know whether they use libcurl or not.  And its code doesn't necessarily
155 run at the start and end of the whole program.
157 A module like this must have global constant functions of its own,
158 just like \fIcurl_global_init()\fP and \fIcurl_global_cleanup()\fP.
159 The module thus has control at the beginning and end of the program
160 and has a place to call the libcurl functions.  Note that if multiple
161 modules in the program use libcurl, they all will separately call the
162 libcurl functions, and that's OK because only the first
163 \fIcurl_global_init()\fP and the last \fIcurl_global_cleanup()\fP in a
164 program change anything.  (libcurl uses a reference count in static
165 memory).
167 In a C++ module, it is common to deal with the global constant
168 situation by defining a special class that represents the global
169 constant environment of the module.  A program always has exactly one
170 object of the class, in static storage.  That way, the program
171 automatically calls the constructor of the object as the program
172 starts up and the destructor as it terminates.  As the author of this
173 libcurl-using module, you can make the constructor call
174 \fIcurl_global_init()\fP and the destructor call
175 \fIcurl_global_cleanup()\fP and satisfy libcurl's requirements without
176 your user having to think about it.
178 \fIcurl_global_init()\fP has an argument that tells what particular
179 parts of the global constant environment to set up.  In order to
180 successfully use any value except \fICURL_GLOBAL_ALL\fP (which says to
181 set up the whole thing), you must have specific knowledge of internal
182 workings of libcurl and all other parts of the program of which it is
183 part.
185 A special part of the global constant environment is the identity of
186 the memory allocator.  \fIcurl_global_init()\fP selects the system
187 default memory allocator, but you can use \fIcurl_global_init_mem()\fP
188 to supply one of your own.  However, there is no way to use
189 \fIcurl_global_init_mem()\fP in a modular program -- all modules in
190 the program that might use libcurl would have to agree on one
191 allocator.
193 There is a failsafe in libcurl that makes it usable in simple
194 situations without you having to worry about the global constant
195 environment at all: \fIcurl_easy_init()\fP sets up the environment
196 itself if it hasn't been done yet.  The resources it acquires to do so
197 get released by the operating system automatically when the program
198 exits.
200 This failsafe feature exists mainly for backward compatibility because
201 there was a time when the global functions didn't exist.  Because it
202 is sufficient only in the simplest of programs, it is not recommended
203 for any program to rely on it.