summaryrefslogtreecommitdiff
path: root/sntp/libevent/sample/https-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'sntp/libevent/sample/https-client.c')
-rw-r--r--sntp/libevent/sample/https-client.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/sntp/libevent/sample/https-client.c b/sntp/libevent/sample/https-client.c
index e13ac4b..fbd5de8 100644
--- a/sntp/libevent/sample/https-client.c
+++ b/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);
}