hurl: change timeout logic and now by default use no time killer - hurl - Gophe… | |
git clone git://git.codemadness.org/hurl | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit c5a5347274765fe9e6a193713653f017ee5d9842 | |
parent 9546c0f17665658befbc25876245acaa9db4b08f | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Sun, 14 Jun 2020 14:13:07 +0200 | |
hurl: change timeout logic and now by default use no time killer | |
... also document in more detail how the time-out logic works. | |
Diffstat: | |
M hurl.1 | 5 ++++- | |
M hurl.c | 26 +++++++++++++++----------- | |
2 files changed, 19 insertions(+), 12 deletions(-) | |
--- | |
diff --git a/hurl.1 b/hurl.1 | |
@@ -29,7 +29,10 @@ Enable legacy ciphers and negotiation for TLS (default off). | |
Maximum size of the data in bytes. | |
.It Fl t Ar timeout | |
Maximum time for the connection and fetching the data in seconds. | |
-The default is 10 seconds. | |
+This sets up a timer that kills the connection after | |
+.Ar timeout | |
+seconds. | |
+The default is to use no timer. | |
.El | |
.Pp | |
For HTTP and HTTPS it will write the data except the header to stdout when the | |
diff --git a/hurl.c b/hurl.c | |
@@ -6,6 +6,7 @@ | |
#include <errno.h> | |
#include <netdb.h> | |
#include <locale.h> | |
+#include <signal.h> | |
#include <stdarg.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
@@ -44,7 +45,7 @@ static const char *config_headers = ""; | |
/* max response size in bytes, 0 is unlimited */ | |
static size_t config_maxresponsesiz = 0; | |
/* time-out in seconds */ | |
-static time_t config_timeout = 10; | |
+static time_t config_timeout = 0; | |
/* legacy ciphers? */ | |
static int config_legacy = 0; | |
/* parsed uri */ | |
@@ -54,6 +55,13 @@ static char *url; | |
/* TLS config */ | |
static struct tls_config *tls_config; | |
+void | |
+sighandler(int signo) | |
+{ | |
+ if (signo == SIGALRM) | |
+ _exit(2); | |
+} | |
+ | |
int | |
parseuri(const char *s, struct uri *u) | |
{ | |
@@ -145,16 +153,6 @@ edial(const char *host, const char *port) | |
continue; | |
} | |
- timeout.tv_sec = config_timeout; | |
- timeout.tv_usec = 0; | |
- if (setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(ti… | |
- err(1, "%s: setsockopt", __func__); | |
- | |
- timeout.tv_sec = config_timeout; | |
- timeout.tv_usec = 0; | |
- if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(ti… | |
- err(1, "%s: setsockopt", __func__); | |
- | |
if (connect(s, res->ai_addr, res->ai_addrlen) == -1) { | |
cause = "connect"; | |
save_errno = errno; | |
@@ -630,6 +628,12 @@ main(int argc, char **argv) | |
if (parseuri(url, &u) == -1) | |
errx(1, "invalid url: %s", url); | |
+ if (config_timeout > 0) { | |
+ signal(SIGALRM, sighandler); | |
+ if (alarm(config_timeout) == -1) | |
+ err(1, "alarm"); | |
+ } | |
+ | |
if (!strcmp(u.proto, "https")) { | |
if (tls_init()) | |
errx(1, "tls_init failed"); |