sample/https-client: add -timeout option

This commit is contained in:
Azat Khuzhin 2015-09-02 19:34:52 +03:00
parent 620aae969c
commit 4637aa8841

View File

@ -96,7 +96,7 @@ static void
syntax(void)
{
fputs("Syntax:\n", stderr);
fputs(" https-client -url <https-url> [-data data-file.bin] [-ignore-cert] [-retries num]\n", stderr);
fputs(" https-client -url <https-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);