Fixed an outdated mention of having keep strings around in curl_easy_setopt
calls. Added a paragraph explaining that libcurl takes care of low-level protocol details. Made a few minor edits.
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
.\" * $Id$
|
.\" * $Id$
|
||||||
.\" **************************************************************************
|
.\" **************************************************************************
|
||||||
.\"
|
.\"
|
||||||
.TH libcurl-tutorial 3 "27 Feb 2007" "libcurl" "libcurl programming"
|
.TH libcurl-tutorial 3 "17 Nov 2008" "libcurl" "libcurl programming"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
libcurl-tutorial \- libcurl programming tutorial
|
libcurl-tutorial \- libcurl programming tutorial
|
||||||
.SH "Objective"
|
.SH "Objective"
|
||||||
@@ -41,7 +41,7 @@ refer to their respective man pages.
|
|||||||
|
|
||||||
.SH "Building"
|
.SH "Building"
|
||||||
There are many different ways to build C programs. This chapter will assume a
|
There are many different ways to build C programs. This chapter will assume a
|
||||||
unix-style build process. If you use a different build system, you can still
|
UNIX-style build process. If you use a different build system, you can still
|
||||||
read this to get general information that may apply to your environment as
|
read this to get general information that may apply to your environment as
|
||||||
well.
|
well.
|
||||||
.IP "Compiling the Program"
|
.IP "Compiling the Program"
|
||||||
@@ -167,11 +167,9 @@ something different. Alas, multiple requests using the same handle will use
|
|||||||
the same options.
|
the same options.
|
||||||
|
|
||||||
Many of the options you set in libcurl are "strings", pointers to data
|
Many of the options you set in libcurl are "strings", pointers to data
|
||||||
terminated with a zero byte. Keep in mind that when you set strings with
|
terminated with a zero byte. When you set strings with
|
||||||
\fIcurl_easy_setopt(3)\fP, libcurl will not copy the data. It will merely
|
\fIcurl_easy_setopt(3)\fP, libcurl makes its own copy so that they don't
|
||||||
point to the data. You MUST make sure that the data remains available for
|
need to be kept around in your application after being set[4].
|
||||||
libcurl to use until finished or until you use the same option again to point
|
|
||||||
to something else.
|
|
||||||
|
|
||||||
One of the most basic properties to set in the handle is the URL. You set
|
One of the most basic properties to set in the handle is the URL. You set
|
||||||
your preferred URL to transfer with CURLOPT_URL in a manner similar to:
|
your preferred URL to transfer with CURLOPT_URL in a manner similar to:
|
||||||
@@ -245,14 +243,20 @@ again. Mind you, it is even preferred that you re-use an existing handle if
|
|||||||
you intend to make another transfer. libcurl will then attempt to re-use the
|
you intend to make another transfer. libcurl will then attempt to re-use the
|
||||||
previous connection.
|
previous connection.
|
||||||
|
|
||||||
|
For some protocols, downloading a file can involve a complicated process of
|
||||||
|
logging in, setting the transfer mode, changing the current directory and
|
||||||
|
finally transferring the file data. libcurl takes care of all that
|
||||||
|
complication for you. Given simply the URL to a file, libcurl will take care
|
||||||
|
of all the details needed to get the file moved from one machine to another.
|
||||||
|
|
||||||
.SH "Multi-threading Issues"
|
.SH "Multi-threading Issues"
|
||||||
The first basic rule is that you must \fBnever\fP share a libcurl handle (be
|
The first basic rule is that you must \fBnever\fP share a libcurl handle (be
|
||||||
it easy or multi or whatever) between multiple threads. Only use one handle in
|
it easy or multi or whatever) between multiple threads. Only use one handle in
|
||||||
one thread at a time.
|
one thread at a time.
|
||||||
|
|
||||||
libcurl is completely thread safe, except for two issues: signals and SSL/TLS
|
libcurl is completely thread safe, except for two issues: signals and SSL/TLS
|
||||||
handlers. Signals are used timeouting name resolves (during DNS lookup) - when
|
handlers. Signals are used for timing out name resolves (during DNS lookup) -
|
||||||
built without c-ares support and not on Windows..
|
when built without c-ares support and not on Windows..
|
||||||
|
|
||||||
If you are accessing HTTPS or FTPS URLs in a multi-threaded manner, you are
|
If you are accessing HTTPS or FTPS URLs in a multi-threaded manner, you are
|
||||||
then of course using the underlying SSL library multi-threaded and those libs
|
then of course using the underlying SSL library multi-threaded and those libs
|
||||||
@@ -350,7 +354,7 @@ knowledge of the expected file size. So, set the upload file size using the
|
|||||||
CURLOPT_INFILESIZE_LARGE for all known file sizes like this[1]:
|
CURLOPT_INFILESIZE_LARGE for all known file sizes like this[1]:
|
||||||
|
|
||||||
.nf
|
.nf
|
||||||
/* in this example, file_size must be an off_t variable */
|
/* in this example, file_size must be an curl_off_t variable */
|
||||||
curl_easy_setopt(easyhandle, CURLOPT_INFILESIZE_LARGE, file_size);
|
curl_easy_setopt(easyhandle, CURLOPT_INFILESIZE_LARGE, file_size);
|
||||||
.fi
|
.fi
|
||||||
|
|
||||||
@@ -389,7 +393,7 @@ to the CURLOPT_USERPWD option like this:
|
|||||||
|
|
||||||
curl_easy_setopt(easyhandle, CURLOPT_PROXYUSERPWD, "myname:thesecret");
|
curl_easy_setopt(easyhandle, CURLOPT_PROXYUSERPWD, "myname:thesecret");
|
||||||
|
|
||||||
There's a long time unix "standard" way of storing ftp user names and
|
There's a long time UNIX "standard" way of storing ftp user names and
|
||||||
passwords, namely in the $HOME/.netrc file. The file should be made private
|
passwords, namely in the $HOME/.netrc file. The file should be made private
|
||||||
so that only the user may read it (see also the "Security Considerations"
|
so that only the user may read it (see also the "Security Considerations"
|
||||||
chapter), as it might contain the password in plain text. libcurl has the
|
chapter), as it might contain the password in plain text. libcurl has the
|
||||||
@@ -1194,6 +1198,9 @@ This happens on Windows machines when libcurl is built and used as a
|
|||||||
DLL. However, you can still do this on Windows if you link with a static
|
DLL. However, you can still do this on Windows if you link with a static
|
||||||
library.
|
library.
|
||||||
.IP "[3]"
|
.IP "[3]"
|
||||||
The curl-config tool is generated at build-time (on unix-like systems) and
|
The curl-config tool is generated at build-time (on UNIX-like systems) and
|
||||||
should be installed with the 'make install' or similar instruction that
|
should be installed with the 'make install' or similar instruction that
|
||||||
installs the library, header files, man pages etc.
|
installs the library, header files, man pages etc.
|
||||||
|
.IP "[4]"
|
||||||
|
This behavior was different in versions before 7.17.0, where strings had to
|
||||||
|
remain valid past the end of the \fIcurl_easy_setopt(3)\fP call.
|
||||||
|
Reference in New Issue
Block a user