curl-library
Re: different "maxdownload" solutions
Date: Mon, 22 Oct 2001 09:51:15 +0200 (MET DST)
On Fri, 19 Oct 2001, Lucas Adamski wrote:
> I've been trying some of these ideas out, but I don't see how they are
> going to work in a multi-threaded environment.
>
> Why? Well, because the callbacks can only access global variables, and
> currently there's no way that I can see of passing a per-instance
> max-download size variable to any of these callbacks without hacking the
> lib source code.
Why? The user-specific data you pass with CURLOPT_FILE is certainly specific
for each curl handle, and thus for every thread. That shouldn't be global
data unless you specificly want it to be that.
You could for example pass a pointer to a private struct of yours, and in
that struct you have a field named 'maxdownload'. You could set that to a
suitable amount for the threads that need it set and have it set to zero for
those that don't (or whatever you think suits your program).
Of course you'd need one struct for each thread, but that shouldn't be any
problem.
> So, these options seem like even more of a hack than the original proposed
> solution.
I don't agree with you here and I can't see why this would be considered "a
hack".
> Given libcurl already has truely esoteric stuff like CURLOPT_INTERFACE
> and CURLOPT_EGDSOCKET, I don't think a simple download size limit is
> unreasonable.
I fail to see how these options could be provided by a callback, given
today's interface or even without getting some very low level knowledge as
those do SSL and socket level fiddling.
> I'd rather have a dedicated MAX_DOWNLOADSIZE option rather than hacking
> the callbacks, so that I can actually differentiate from a real callback
> error.
I can agree with you that is would be a cool addition to somehow better
control what kind of return code that is returned
But what is a "real callback" error to you? Since you get your private struct
passed to your callback, you could easily have a field named
'maximum_reached' that you set to TRUE when you return an error. Then, in
your code that checks for error from *perform(), you check that struct to see
if the error was caused by maximum_reached being TRUE or not.
I want libcurl to offer generic ways to implement specific stuff. I think
this maxdownload is a specific check that could be done using the generic
callbacks.
-- Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/Received on 2001-10-22