From: Felix Fietkau Date: Sat, 16 Jan 2016 12:08:45 +0000 (+0100) Subject: uclient-fetch: add support for --timeout X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b94caa406f4e5c1db4691735ba4969b002dc978f;p=oweals%2Fuclient.git uclient-fetch: add support for --timeout Signed-off-by: Felix Fietkau --- diff --git a/uclient-fetch.c b/uclient-fetch.c index d4b9527..7418f82 100644 --- a/uclient-fetch.c +++ b/uclient-fetch.c @@ -52,6 +52,7 @@ static char *password; static char *auth_str; static char **urls; static int n_urls; +static int timeout; static void request_done(struct uclient *cl); @@ -158,6 +159,9 @@ static int init_request(struct uclient *cl) out_bytes = 0; uclient_http_set_ssl_ctx(cl, ssl_ops, ssl_ctx, verify); + if (timeout) + cl->timeout_msecs = timeout * 1000; + rc = uclient_connect(cl); if (rc) return rc; @@ -271,6 +275,7 @@ static int usage(const char *progname) " --user-agent|-U Set HTTP user agent\n" " --post-data=STRING use the POST method; send STRING as the data\n" " --spider|-s Spider mode - only check file existence\n" + " --timeout=N|-T N Set connect/request timeout to N seconds\n" "\n" "HTTPS options:\n" " --ca-certificate=: Load CA certificates from file \n" @@ -318,6 +323,7 @@ enum { L_USER_AGENT, L_POST_DATA, L_SPIDER, + L_TIMEOUT, }; static const struct option longopts[] = { @@ -328,6 +334,7 @@ static const struct option longopts[] = { [L_USER_AGENT] = { "user-agent", required_argument }, [L_POST_DATA] = { "post-data", required_argument }, [L_SPIDER] = { "spider", no_argument }, + [L_TIMEOUT] = { "timeout", required_argument }, {} }; @@ -377,6 +384,9 @@ int main(int argc, char **argv) case L_SPIDER: no_output = true; break; + case L_TIMEOUT: + timeout = atoi(optarg); + break; default: return usage(progname); } @@ -393,6 +403,9 @@ int main(int argc, char **argv) case 's': no_output = true; break; + case 'T': + timeout = atoi(optarg); + break; default: return usage(progname); }