cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: curl cookie jar

From: <curl_at_thewrittenword.com>
Date: Tue, 28 Aug 2001 08:25:40 -0500

On Tue, Aug 28, 2001 at 02:56:59PM +0200, Ingo Wilken wrote:
> > 1. File locking. It was said we need file locking to have several invoked
> > curls all write to the same destination file. I have serious doubts
> > around this. Not only do I suspect that people will still make mistakes
> > when using a single output file, but we'll also get problems with systems
> > that don't do proper locking (like various OSes or just systems running
> > on NFS or similar).
>
> On a similar note, we are investigating methods to allow several curl
> handles (even used by different threads) to share a single cookie list.
>
> The solution proposed by me is to create data type curl_cookie_list
> (with no inherent mutex locking) and have curl call optional functions
> whenever it wants to access the list:
>
> curl_cookie_list clist;
> /* build initial cookie list somehow */
> curl_easy_setopt(CURL_COOKIELIST, &clist);
> curl_easy_setopt(CURL_COOKIELIST_LOCK, lockfunction);
> curl_easy_setopt(CURL_COOKIELIST_UNLOCK, unlockfunction);
>
> curl would call lockfunction whenever it wants to read from the cookie list
> (if lockfunction != NULL), und unlockfunction afterwards. The same happens
> whenever curl wants to add a cookie to the list. By default, both function
> pointers are NULL, and the clist is not thread-safe/shareable. If the
> application wants a shareable list, it creates a mutex for this list (in
> whatever thread-system it uses, for example pthreads) and passes functions
> to (un)lock this mutex to curl - voila, a shareable clist.
>
> Any comments to this?

Who provides lockfunction? The caller? Does this mean all callers
would need to implement fcntl-style locking? Seems like a bit much for
the callers. I think there should be some default that is
cross-platform and allow the ability for the caller to specify a
custom lock function.

Actually, should we even bother with allowing a custom lock function?
In this case, how about having the caller synchronize everything? This
would change the above to:
  curl_easy_setopt(CURL_COOKIELIST_LOCK, lock);
  curl_easy_setopt(CURL_COOKIELIST_UNLOCK, unlock);

where lock and unlock are booleans. If true, the system fcntl locking
would be used. If false, it's up to the caller to synchronize.

-- 
albert chin (china_at_thewrittenword.com)
Received on 2001-08-28