cURL / Mailing Lists / curl-library / Single Mail

curl-library

Using options CURLOPT_COOKIEFILE & CURLOPT_COOKIEJAR

From: Edward Chan <echan_at_macromedia.com>
Date: Tue, 2 Sep 2003 14:27:55 -0700

Hi there,

I was stepping through the code and stumbled on this as the likely cause of
a problem I'm having, and I wanted to ask if this is required. I'm trying
to use a cookie file to read/write from. I did this by doing,

                CURL* handle = curl_easy_init();

                ...

                curl_easy_setopt(handle, CURLOPT_COOKIEFILE,
"c:\\cookie.txt" );
                curl_easy_setopt(handle, CURLOPT_COOKIEJAR,
"c:\\cookie.txt" );

                ...

                curl_easy_perform(handle);
                curl_easy_cleanup(handle);

However, I find that some times, the http request fails. I noticed that if
I do not call curl_easy_cleanup(), then all is well. So I started stepping
into the libcurl code. In url.c, in Curl_close(), it tries to lock the
cookie file by calling Curl_share_lock(), then write to the file, then
unlock. However, inside Curl_share_lock(), it fails because there is no
share set up. Do I need to setup a share if I have multiple threads that
may be accessing the cookie file at the same time? I didn't see anything in
the docs about doing this. But I did find some code under the libtest
directory that does this, in libtest\lib506.c. The code sets the option,
CURLOPT_SHARE, but I didn't find this option in the docs. It seems like
this is probably required in a multithreaded environment, correct?

Is there a good resource on the proper usage of cookie files?

Thanks,
Ed

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-09-02