mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
sample/https-client: add -timeout option
This commit is contained in:
parent
620aae969c
commit
4637aa8841
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user