cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: [PATCH] Callback to abort libcurl when receiving a signal

From: Pierre Ynard <linkfanel_at_yahoo.fr>
Date: Thu, 6 Mar 2008 10:05:49 +0100

> Once that said and taking in account that the network call will be
> retried upon EINTR, you could still want it to fail for some very
> specific signal, lets say SIGTERM, how would you do it ?
>
> Remember that libcurl is a library, that it widely used in
> multi-threaded environments, and that it might be compiled/deployed as
> a shared library and used by different apps on the same system.

I wouldn't really handle any specific signal in libcurl itself, because
it is too much binding to some specific behavior and could not be very
portable. Rather, I would offload the signal processing to the caller
application, on a per-handle basis, with a callback option: up to the
caller application to decide which signals it handles, which ones it
blocks, install its small signal handlers, and register the callback
function to libcurl.

Then, basically whenever poll() is interrupted and returns with EINTR,
this callback is called, and based on whatever signal handler that has
already been executed and whatever data specific to the application, a
non-zero return code may be returned or not by the callback, to tell
libcurl to abort operations. That's what my patch does. Most of the
time, it wouldn't change anything at all if the application doesn't use
this option.

-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."
Received on 2008-03-06