]> granicus.if.org Git - libevent/commitdiff
https-client: add -retries argument, for connection retries
authorAzat Khuzhin <a3at.mail@gmail.com>
Sun, 21 Sep 2014 14:36:29 +0000 (18:36 +0400)
committerAzat Khuzhin <a3at.mail@gmail.com>
Sun, 21 Sep 2014 19:48:07 +0000 (23:48 +0400)
Using evhttp_connection_set_retries() API.

sample/https-client.c

index b5f0b1ae57c05e9a528889427864a46b67b80791..eea61e5d3bb0fc4dd1366535dcf83fe339c9aaf7 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]\n", stderr);
+       fputs("   https-client -url <https-url> [-data data-file.bin] [-ignore-cert] [-retries num]\n", stderr);
        fputs("Example:\n", stderr);
        fputs("   https-client -url https://ip.appspot.com/\n", stderr);
 
@@ -195,6 +195,7 @@ main(int argc, char **argv)
        const char *scheme, *host, *path, *query;
        char uri[256];
        int port;
+       int retries = 0;
 
        SSL_CTX *ssl_ctx;
        SSL *ssl;
@@ -221,6 +222,12 @@ main(int argc, char **argv)
                        } else {
                                syntax();
                        }
+               } else if (!strcmp("-retries", argv[i])) {
+                       if (i < argc - 1) {
+                               retries = atoi(argv[i + 1]);
+                       } else {
+                               syntax();
+                       }
                } else if (!strcmp("-help", argv[i])) {
                        syntax();
                }
@@ -373,6 +380,10 @@ main(int argc, char **argv)
                return 1;
        }
 
+       if (retries > 0) {
+               evhttp_connection_set_retries(evcon, retries);
+       }
+
        // Fire off the request
        req = evhttp_request_new(http_request_done, bev);
        if (req == NULL) {