From: Azat Khuzhin Date: Wed, 2 Sep 2015 16:34:52 +0000 (+0300) Subject: sample/https-client: add -timeout option X-Git-Tag: release-2.1.6-beta~90^2~53 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4637aa8841c71deb43d1bc34f0d70a1604bbacb5;p=libevent sample/https-client: add -timeout option --- diff --git a/sample/https-client.c b/sample/https-client.c index 9d2c9e35..d0f9d070 100644 --- a/sample/https-client.c +++ b/sample/https-client.c @@ -96,7 +96,7 @@ static void syntax(void) { fputs("Syntax:\n", stderr); - fputs(" https-client -url [-data data-file.bin] [-ignore-cert] [-retries num]\n", stderr); + fputs(" https-client -url [-data data-file.bin] [-ignore-cert] [-retries num] [-timeout sec]\n", stderr); fputs("Example:\n", stderr); fputs(" https-client -url https://ip.appspot.com/\n", stderr); } @@ -193,6 +193,7 @@ main(int argc, char **argv) char uri[256]; int port; int retries = 0; + int timeout = -1; SSL_CTX *ssl_ctx = NULL; SSL *ssl = NULL; @@ -230,6 +231,13 @@ main(int argc, char **argv) syntax(); goto error; } + } else if (!strcmp("-timeout", argv[i])) { + if (i < argc - 1) { + timeout = atoi(argv[i + 1]); + } else { + syntax(); + goto error; + } } else if (!strcmp("-help", argv[i])) { syntax(); goto error; @@ -399,6 +407,9 @@ main(int argc, char **argv) if (retries > 0) { evhttp_connection_set_retries(evcon, retries); } + if (timeout >= 0) { + evhttp_connection_set_timeout(evcon, timeout); + } // Fire off the request req = evhttp_request_new(http_request_done, bev);