version 1.24, 2018/07/13 18:36:56 |
version 1.25, 2018/08/11 16:07:36 |
|
|
|
|
static void s_time_usage(void); |
static void s_time_usage(void); |
static SSL *doConnection(SSL * scon); |
static SSL *doConnection(SSL * scon); |
|
static int benchmark(int); |
|
|
static SSL_CTX *tm_ctx = NULL; |
static SSL_CTX *tm_ctx = NULL; |
static const SSL_METHOD *s_time_meth = NULL; |
static const SSL_METHOD *s_time_meth = NULL; |
|
|
int |
int |
s_time_main(int argc, char **argv) |
s_time_main(int argc, char **argv) |
{ |
{ |
double totalTime = 0.0; |
|
int nConn = 0; |
|
SSL *scon = NULL; |
|
time_t finishtime; |
|
int ret = 1; |
int ret = 1; |
char buf[1024 * 8]; |
|
int ver; |
|
|
|
if (single_execution) { |
if (single_execution) { |
if (pledge("stdio rpath inet dns", NULL) == -1) { |
if (pledge("stdio rpath inet dns", NULL) == -1) { |
|
|
|
|
/* Loop and time how long it takes to make connections */ |
/* Loop and time how long it takes to make connections */ |
|
|
bytes_read = 0; |
if (benchmark(0)) |
finishtime = time(NULL) + s_time_config.maxtime; |
goto end; |
tm_Time_F(START); |
|
for (;;) { |
|
if (finishtime < time(NULL)) |
|
break; |
|
if ((scon = doConnection(NULL)) == NULL) |
|
goto end; |
|
|
|
if (s_time_config.www_path != NULL) { |
|
int i, retval = snprintf(buf, sizeof buf, |
|
"GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); |
|
if ((size_t)retval >= sizeof buf) { |
|
fprintf(stderr, "URL too long\n"); |
|
goto end; |
|
} |
|
SSL_write(scon, buf, strlen(buf)); |
|
while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) |
|
bytes_read += i; |
|
} |
|
if (s_time_config.no_shutdown) |
|
SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | |
|
SSL_RECEIVED_SHUTDOWN); |
|
else |
|
SSL_shutdown(scon); |
|
|
|
nConn += 1; |
|
if (SSL_session_reused(scon)) |
|
ver = 'r'; |
|
else { |
|
ver = SSL_version(scon); |
|
if (ver == TLS1_VERSION) |
|
ver = 't'; |
|
else if (ver == SSL3_VERSION) |
|
ver = '3'; |
|
else if (ver == SSL2_VERSION) |
|
ver = '2'; |
|
else |
|
ver = '*'; |
|
} |
|
fputc(ver, stdout); |
|
fflush(stdout); |
|
|
|
SSL_free(scon); |
|
scon = NULL; |
|
} |
|
totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ |
|
|
|
printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", |
|
nConn, totalTime, ((double) nConn / totalTime), bytes_read); |
|
printf("%d connections in %lld real seconds, %ld bytes read per connection\n", |
|
nConn, |
|
(long long)(time(NULL) - finishtime + s_time_config.maxtime), |
|
bytes_read / nConn); |
|
|
|
/* |
/* |
* Now loop and time connections using the same session id over and |
* Now loop and time connections using the same session id over and |
* over |
* over |
|
|
goto end; |
goto end; |
printf("\n\nNow timing with session id reuse.\n"); |
printf("\n\nNow timing with session id reuse.\n"); |
|
|
/* Get an SSL object so we can reuse the session id */ |
if (benchmark(1)) |
if ((scon = doConnection(NULL)) == NULL) { |
|
fprintf(stderr, "Unable to get connection\n"); |
|
goto end; |
goto end; |
} |
|
if (s_time_config.www_path != NULL) { |
|
int retval = snprintf(buf, sizeof buf, |
|
"GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); |
|
if ((size_t)retval >= sizeof buf) { |
|
fprintf(stderr, "URL too long\n"); |
|
goto end; |
|
} |
|
SSL_write(scon, buf, strlen(buf)); |
|
while (SSL_read(scon, buf, sizeof(buf)) > 0); |
|
} |
|
if (s_time_config.no_shutdown) |
|
SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | |
|
SSL_RECEIVED_SHUTDOWN); |
|
else |
|
SSL_shutdown(scon); |
|
|
|
nConn = 0; |
|
totalTime = 0.0; |
|
|
|
finishtime = time(NULL) + s_time_config.maxtime; |
|
|
|
printf("starting\n"); |
|
bytes_read = 0; |
|
tm_Time_F(START); |
|
|
|
for (;;) { |
|
if (finishtime < time(NULL)) |
|
break; |
|
if ((doConnection(scon)) == NULL) |
|
goto end; |
|
|
|
if (s_time_config.www_path) { |
|
int i, retval = snprintf(buf, sizeof buf, |
|
"GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); |
|
if ((size_t)retval >= sizeof buf) { |
|
fprintf(stderr, "URL too long\n"); |
|
goto end; |
|
} |
|
SSL_write(scon, buf, strlen(buf)); |
|
while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) |
|
bytes_read += i; |
|
} |
|
if (s_time_config.no_shutdown) |
|
SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | |
|
SSL_RECEIVED_SHUTDOWN); |
|
else |
|
SSL_shutdown(scon); |
|
|
|
nConn += 1; |
|
if (SSL_session_reused(scon)) |
|
ver = 'r'; |
|
else { |
|
ver = SSL_version(scon); |
|
if (ver == TLS1_VERSION) |
|
ver = 't'; |
|
else if (ver == SSL3_VERSION) |
|
ver = '3'; |
|
else if (ver == SSL2_VERSION) |
|
ver = '2'; |
|
else |
|
ver = '*'; |
|
} |
|
fputc(ver, stdout); |
|
fflush(stdout); |
|
} |
|
totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ |
|
|
|
printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read); |
|
printf("%d connections in %lld real seconds, %ld bytes read per connection\n", |
|
nConn, |
|
(long long)(time(NULL) - finishtime + s_time_config.maxtime), |
|
bytes_read / nConn); |
|
|
|
ret = 0; |
ret = 0; |
end: |
end: |
SSL_free(scon); |
|
|
|
if (tm_ctx != NULL) { |
if (tm_ctx != NULL) { |
SSL_CTX_free(tm_ctx); |
SSL_CTX_free(tm_ctx); |
tm_ctx = NULL; |
tm_ctx = NULL; |
|
|
return NULL; |
return NULL; |
} |
} |
return serverCon; |
return serverCon; |
|
} |
|
|
|
static int |
|
benchmark(int reuse_session) |
|
{ |
|
double totalTime = 0.0; |
|
int nConn = 0; |
|
SSL *scon = NULL; |
|
time_t finishtime; |
|
int ret = 1; |
|
char buf[1024 * 8]; |
|
int ver; |
|
|
|
if (reuse_session) { |
|
/* Get an SSL object so we can reuse the session id */ |
|
if ((scon = doConnection(NULL)) == NULL) { |
|
fprintf(stderr, "Unable to get connection\n"); |
|
goto end; |
|
} |
|
if (s_time_config.www_path != NULL) { |
|
int retval = snprintf(buf, sizeof buf, |
|
"GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); |
|
if ((size_t)retval >= sizeof buf) { |
|
fprintf(stderr, "URL too long\n"); |
|
goto end; |
|
} |
|
SSL_write(scon, buf, strlen(buf)); |
|
while (SSL_read(scon, buf, sizeof(buf)) > 0); |
|
} |
|
if (s_time_config.no_shutdown) |
|
SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | |
|
SSL_RECEIVED_SHUTDOWN); |
|
else |
|
SSL_shutdown(scon); |
|
printf("starting\n"); |
|
} |
|
|
|
nConn = 0; |
|
totalTime = 0.0; |
|
|
|
finishtime = time(NULL) + s_time_config.maxtime; |
|
|
|
bytes_read = 0; |
|
tm_Time_F(START); |
|
|
|
for (;;) { |
|
if (finishtime < time(NULL)) |
|
break; |
|
if ((scon = doConnection(reuse_session ? scon : NULL)) == NULL) |
|
goto end; |
|
|
|
if (s_time_config.www_path != NULL) { |
|
int i, retval = snprintf(buf, sizeof buf, |
|
"GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); |
|
if ((size_t)retval >= sizeof buf) { |
|
fprintf(stderr, "URL too long\n"); |
|
goto end; |
|
} |
|
SSL_write(scon, buf, strlen(buf)); |
|
while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) |
|
bytes_read += i; |
|
} |
|
if (s_time_config.no_shutdown) |
|
SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | |
|
SSL_RECEIVED_SHUTDOWN); |
|
else |
|
SSL_shutdown(scon); |
|
|
|
nConn += 1; |
|
if (SSL_session_reused(scon)) |
|
ver = 'r'; |
|
else { |
|
ver = SSL_version(scon); |
|
if (ver == TLS1_VERSION) |
|
ver = 't'; |
|
else if (ver == SSL3_VERSION) |
|
ver = '3'; |
|
else if (ver == SSL2_VERSION) |
|
ver = '2'; |
|
else |
|
ver = '*'; |
|
} |
|
fputc(ver, stdout); |
|
fflush(stdout); |
|
|
|
if (!reuse_session) { |
|
SSL_free(scon); |
|
scon = NULL; |
|
} |
|
} |
|
totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ |
|
|
|
printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", |
|
nConn, totalTime, ((double) nConn / totalTime), bytes_read); |
|
printf("%d connections in %lld real seconds, %ld bytes read per connection\n", |
|
nConn, |
|
(long long)(time(NULL) - finishtime + s_time_config.maxtime), |
|
bytes_read / nConn); |
|
|
|
ret = 0; |
|
end: |
|
SSL_free(scon); |
|
return ret; |
} |
} |