]> granicus.if.org Git - libevent/commitdiff
sample/https-client: add -timeout option
authorAzat Khuzhin <a3at.mail@gmail.com>
Wed, 2 Sep 2015 16:34:52 +0000 (19:34 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Wed, 2 Sep 2015 16:34:52 +0000 (19:34 +0300)
sample/https-client.c

index 9d2c9e35d0ac3b7131a55561d8c422286dd95ab1..d0f9d070c710f42e7608dfce2d34e3e2b0942f46 100644 (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);