curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Aborting curl request when SIGTERM received

From: Dan Fandrich via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 2 Apr 2019 12:40:55 +0200

On Tue, Apr 02, 2019 at 03:39:14PM +0530, Prashant Shubham via curl-library wrote:
> If there is an ongoing curl request and the application receives
> SIGTERM, is there a way curl can acknowledge and abort the request in
> middle.

The most reliable way to do this is probably to write a SIGTERM handler that
sets a global flag, then check the flag from the CURLOPT_XFERINFOFUNCTION
callback function and return non-zero when it's set. This will cause the
transfer to be aborted and return CURLE_ABORTED_BY_CALLBACK.
CURLOPT_XFERINFOFUNCTION is called fairly frequently even when nothing is
happening so there won't be much of a delay before the signal is acknowledged.
You can also check the flag in your read/write callback function to reduce the
delay even further in the case of an ongoing transfer.

>>> Dan
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-04-02