curl-library
Re: Usage of CURLOPT_ERRORBUFFER
Date: Sat, 23 Dec 2017 12:29:23 -0800
On 12/23/2017 11:02 AM, Martin Galvan via curl-library wrote:
> Hi all,
>
> The docs for CURLOPT_ERRORBUFFER say:
>
> "You must keep the associated buffer available until libcurl no longer
> needs it. Failing to do so will cause very odd behavior or even
> crashes. libcurl will need it until you call curl_easy_cleanup or you
> set the same option again to use a different pointer. "
>
> While this is an odd design choice, I wonder what "keeping the buffer
> available" means in this context. Does it mean that it should remain
> allocated, or that its contents shouldn't be touched? What happens if
> I want to make multiple requests using the same bufffer, and zero it
> before each request? Should I call curl_easy_cleanup, then
> curl_easy_init again before each new request?
> -------------------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>
>
This isn't an odd choice at all; a libcurl session could be active for a
very long time, and there may be many errors reported. The buffer would
be used each time there is an error. The help text points out that
libcurl has no way to know when you have released (freed) the buffer, so
you must notify it in some way. If you think the text is unclear you
are welcome to suggest changes.
As for zeroing the buffer before each request, you could do that. The
sample code does. It strongly suggests that not all error conditions
will cause the buffer to be overwritten. You don't need to zero the
buffer (e.g. by writing a '\0' into the first byte) before performing an
action unless you plan to check it immediately after the action.
You don't need to call curl_easy_cleanup() or curl_easy_init() each time.
-- David Chapman dcchapman_at_acm.org Chapman Consulting -- San Jose, CA EDA Software Developer, Expert Witness www.chapman-consulting-sj.com ------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.htmlReceived on 2017-12-23