diff options
author | gjb <gjb@FreeBSD.org> | 2015-05-06 11:50:30 +0000 |
---|---|---|
committer | gjb <gjb@FreeBSD.org> | 2015-05-06 11:50:30 +0000 |
commit | e9b794a6dfdf28ce835f5730e5884b97bc62aa19 (patch) | |
tree | 759e7355bf352e43e4a156a773a28d3d9fdbcad7 /contrib/ntp/sntp/libevent/sample/https-client.c | |
parent | 55e5b36d38ff95ded004ed97fe9ed303abb36184 (diff) | |
parent | 462d48d659bae28be32c0d488ddeeaaf99d87bae (diff) | |
download | FreeBSD-src-e9b794a6dfdf28ce835f5730e5884b97bc62aa19.zip FreeBSD-src-e9b794a6dfdf28ce835f5730e5884b97bc62aa19.tar.gz |
MFH: r282315-r282534
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'contrib/ntp/sntp/libevent/sample/https-client.c')
-rw-r--r-- | contrib/ntp/sntp/libevent/sample/https-client.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/contrib/ntp/sntp/libevent/sample/https-client.c b/contrib/ntp/sntp/libevent/sample/https-client.c index e13ac4b..fbd5de8 100644 --- a/contrib/ntp/sntp/libevent/sample/https-client.c +++ b/contrib/ntp/sntp/libevent/sample/https-client.c @@ -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(); } @@ -346,8 +353,10 @@ main(int argc, char **argv) die_openssl("SSL_new()"); } + #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME // Set hostname for SNI extension SSL_set_tlsext_host_name(ssl, host); + #endif if (strcasecmp(scheme, "http") == 0) { bev = bufferevent_socket_new(base, -1, BEV_OPT_CLOSE_ON_FREE); @@ -373,6 +382,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) { @@ -402,7 +415,7 @@ main(int argc, char **argv) evbuffer_add(output_buffer, buf, s); bytes += s; } - evutil_snprintf(buf, sizeof(buf)-1, "%lu", bytes); + evutil_snprintf(buf, sizeof(buf)-1, "%lu", (unsigned long)bytes); evhttp_add_header(output_headers, "Content-Length", buf); fclose(f); } |