From 3c49b405de4fbf1fd7127f91908261268640e54f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 Jun 2002 15:10:18 +0000 Subject: Now uses sigsetjmp() and siglongjmp() to bail out from slow name lookups in case a timeout is set. This seems to work. God knows if it is good enough or what kind of side-effects we introduce here and now. I'll close my eyes and cross my fingers. Hard. --- lib/hostip.c | 17 +++++++++++++++++ lib/url.c | 9 +++++++++ 2 files changed, 26 insertions(+) (limited to 'lib') diff --git a/lib/hostip.c b/lib/hostip.c index c6cd28b75..84ced78de 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -56,6 +56,10 @@ #endif #endif +#ifdef HAVE_SETJMP_H +#include +#endif + #include "urldata.h" #include "sendf.h" #include "hostip.h" @@ -191,6 +195,11 @@ hostcache_prune(curl_hash *hostcache, int cache_timeout, int now) return (__v); \ } +#ifdef HAVE_SIGSETJMP +/* Beware this is a global and unique instance */ +sigjmp_buf curl_jmpenv; +#endif + Curl_addrinfo *Curl_resolv(struct SessionHandle *data, char *hostname, int port) @@ -201,6 +210,14 @@ Curl_addrinfo *Curl_resolv(struct SessionHandle *data, time_t now; char *bufp; +#ifdef HAVE_SIGSETJMP + if(sigsetjmp(curl_jmpenv, 1) != 0) { + /* this is coming from a siglongjmp() */ + failf(data, "name lookup time-outed"); + return NULL; + } +#endif + /* If the host cache timeout is 0, we don't do DNS cach'ing so fall through */ if (data->set.dns_cache_timeout == 0) { diff --git a/lib/url.c b/lib/url.c index fc4529c8e..44c13ccb1 100644 --- a/lib/url.c +++ b/lib/url.c @@ -72,6 +72,10 @@ #include #endif +#ifdef HAVE_SETJMP_H +#include +#endif + #ifndef HAVE_SELECT #error "We can't compile without select() support!" #endif @@ -120,6 +124,7 @@ #ifdef KRB4 #include "security.h" #endif + /* The last #include file should be: */ #ifdef MALLOCDEBUG #include "memdebug.h" @@ -143,6 +148,10 @@ RETSIGTYPE alarmfunc(int signal) { /* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */ (void)signal; +#ifdef HAVE_SIGSETJMP + extern sigjmp_buf curl_jmpenv; + siglongjmp(curl_jmpenv, 1); +#endif return; } #endif -- cgit v1.2.3