cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Is it safe to set curl options inside a callback function?

From: Milmar Tan <milmarqtan_at_gmail.com>
Date: Sat, 29 Aug 2009 19:06:53 +0800

On Sat, Aug 29, 2009 at 1:19 PM, Jeff Pohlmeyer<yetanothergeek_at_gmail.com> wrote:
> On Fri, Aug 28, 2009, Milmar Tan wrote:
>
>
>> I can't set the write callback before the header callback gets called
>> because I haven't yet allocated the buffer that will hold the image at
>> that time.
>
> The write callback does not normally get called until *after* all the
> headers have been received. When you get an empty header with just
> the \r\n you'll know it's the last header, so if you haven't gotten
> a content-length by then, you can return -1 to abort the transfer
> from the header callback, before the write callback ever gets called.
> But if you decide later to enable CURLOPT_FOLLOWLOCATION, things will
> get even more complicated.

What do you mean that things will get more complicated if I enable
CURLOPT_FOLLOWLOCATION?

>
>
>
>> My initial tests show the above hack works. But it's quite scary to
>> suddenly get an error with the hack in place during production of the
>> device.
>
> Then my advice would be to find another way to accomplish your task.
> There is really no point in fiddling with libcurl's internal state
> while a transfer is in progress. What you want can certainly be
> accomplished without that.
>

I'm now starting to believe that meddling with curl options while
transferring is not a good idea.

Thanks for these clarifications on my misunderstandings about some
CURL options and behavior.

Regards,

Milmar
Received on 2009-08-29