=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/openssl/s_time.c,v retrieving revision 1.24 retrieving revision 1.25 diff -c -r1.24 -r1.25 *** src/usr.bin/openssl/s_time.c 2018/07/13 18:36:56 1.24 --- src/usr.bin/openssl/s_time.c 2018/08/11 16:07:36 1.25 *************** *** 1,4 **** ! /* $OpenBSD: s_time.c,v 1.24 2018/07/13 18:36:56 cheloha Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * --- 1,4 ---- ! /* $OpenBSD: s_time.c,v 1.25 2018/08/11 16:07:36 cheloha Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * *************** *** 91,96 **** --- 91,97 ---- static void s_time_usage(void); static SSL *doConnection(SSL * scon); + static int benchmark(int); static SSL_CTX *tm_ctx = NULL; static const SSL_METHOD *s_time_meth = NULL; *************** *** 244,256 **** int s_time_main(int argc, char **argv) { - double totalTime = 0.0; - int nConn = 0; - SSL *scon = NULL; - time_t finishtime; int ret = 1; - char buf[1024 * 8]; - int ver; if (single_execution) { if (pledge("stdio rpath inet dns", NULL) == -1) { --- 245,251 ---- *************** *** 328,388 **** /* Loop and time how long it takes to make connections */ ! bytes_read = 0; ! finishtime = time(NULL) + s_time_config.maxtime; ! 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 * over --- 323,331 ---- /* Loop and time how long it takes to make connections */ ! if (benchmark(0)) ! goto end; /* * Now loop and time connections using the same session id over and * over *************** *** 393,480 **** goto end; printf("\n\nNow timing with session id reuse.\n"); ! /* 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); - 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; end: - SSL_free(scon); - if (tm_ctx != NULL) { SSL_CTX_free(tm_ctx); tm_ctx = NULL; --- 336,346 ---- goto end; printf("\n\nNow timing with session id reuse.\n"); ! if (benchmark(1)) goto end; ret = 0; end: if (tm_ctx != NULL) { SSL_CTX_free(tm_ctx); tm_ctx = NULL; *************** *** 541,544 **** --- 407,513 ---- return NULL; } 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; }