Browse files

Fix previous fix for older curl's without millisecond timestamps.

Do a configure.ac check of the options (checking on ifdef's don't work
as the values are enum's). Also update the 02 test case to work when
millisecond timestamps aren't available.
  • Loading branch information...
1 parent db568f3 commit 2cfa61dc4d6cadb352e26abda885d6ba614e4845 @mbgrydeland mbgrydeland committed Feb 12, 2013
Showing with 34 additions and 5 deletions.
  1. +27 −0 configure.ac
  2. +3 −3 src/tests/test02.vtc
  3. +4 −2 src/vmod_curl.c
View
27 configure.ac
@@ -66,6 +66,33 @@ if test "x$VMODDIR" = x; then
fi
fi
+# check if curl supports ms timeout settings
+save_CFLAGS="${CFLAGS}"
+save_LIBS="${LIBS}"
+CFLAGS="${CFLAGS} ${CURL_CFLAGS}"
+LIBS="${LIBS} ${CURL_LIBS}"
+AC_CACHE_CHECK([for curl ms timeout settings],
+ [ac_cv_curl_ms_timeout],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([[
+#include <stdio.h>
+#include <curl/curl.h>
+ ]],[[
+CURL *curl_handle;
+curl_handle = curl_easy_init();
+curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, 10);
+curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, 10);
+return (0);
+ ]])],
+ [ac_cv_curl_ms_timeout=yes],
+ [ac_cv_curl_ms_timeout=no])
+ ])
+if test "$ac_cv_curl_ms_timeout" = yes; then
+ AC_DEFINE([CURL_TIMEOUTMS_WORKS], [1], [Define if curl supports ms timeout])
+fi
+CFLAGS="${save_CFLAGS}"
+LIBS="${save_LIBS}"
+
AC_CONFIG_FILES([
Makefile
src/Makefile
View
6 src/tests/test02.vtc
@@ -2,15 +2,15 @@ varnishtest "Test data timeout"
server s1 {
rxreq
- delay 0.5
+ delay 2
txresp -hdr "Foo: bar"
} -start
varnish v1 -vcl+backend {
import curl from "${vmod_topbuild}/src/.libs/libvmod_curl.so";
sub vcl_recv {
- curl.set_timeout(1);
- curl.set_connect_timeout(1);
+ curl.set_timeout(1000);
+ curl.set_connect_timeout(1000);
curl.fetch("http://${s1_addr}:${s1_port}");
error 200;
}
View
6 src/vmod_curl.c
@@ -11,6 +11,8 @@
#include "vcc_if.h"
#include "vmod_curl.h"
+#include "config.h"
+
struct hdr {
char *key;
char *value;
@@ -198,15 +200,15 @@ void vmod_fetch(struct sess *sp, const char *url)
curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, c);
if (c->timeout_ms > 0) {
-#ifdef CURLOPT_TIMEOUT_MS
+#ifdef CURL_TIMEOUTMS_WORKS
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, c->timeout_ms);
#else
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, c->timeout_ms / 1000);
#endif
}
if (c->connect_timeout_ms > 0) {
-#ifdef CURLOPT_CONNECTTIMEOUT_MS
+#ifdef CURL_TIMEOUTMS_WORKS
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT_MS, c->connect_timeout_ms);
#else
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, c->connect_timeout_ms / 1000);

0 comments on commit 2cfa61d

Please sign in to comment.