📄 s_time.c
字号:
*/#define START 0#define STOP 1static double tm_Time_F(int s) { static double ret;#ifdef TIMES static struct tms tstart,tend; if(s == START) { times(&tstart); return(0); } else { times(&tend); ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; return((ret == 0.0)?1e-6:ret); }#elif defined(OPENSSL_SYS_NETWARE) static clock_t tstart,tend; if (s == START) { tstart=clock(); return(0); } else { tend=clock(); ret=(double)((double)(tend)-(double)(tstart)); return((ret < 0.001)?0.001:ret); }#elif defined(OPENSSL_SYS_VXWORKS) { static unsigned long tick_start, tick_end; if( s == START ) { tick_start = tickGet(); return 0; } else { tick_end = tickGet(); ret = (double)(tick_end - tick_start) / (double)sysClkRateGet(); return((ret == 0.0)?1e-6:ret); } }#else /* !times() */ static struct timeb tstart,tend; long i; if(s == START) { ftime(&tstart); return(0); } else { ftime(&tend); i=(long)tend.millitm-(long)tstart.millitm; ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; return((ret == 0.0)?1e-6:ret); }#endif}/*********************************************************************** * MAIN - main processing area for client * real name depends on MONOLITH */int MAIN(int, char **);int MAIN(int argc, char **argv) { double totalTime = 0.0; int nConn = 0; SSL *scon=NULL; long finishtime=0; int ret=1,i; MS_STATIC char buf[1024*8]; int ver; apps_startup(); s_time_init(); if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3) s_time_meth=SSLv23_client_method();#elif !defined(OPENSSL_NO_SSL3) s_time_meth=SSLv3_client_method();#elif !defined(OPENSSL_NO_SSL2) s_time_meth=SSLv2_client_method();#endif /* parse the command line arguments */ if( parseArgs( argc, argv ) < 0 ) goto end; OpenSSL_add_ssl_algorithms(); if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1); SSL_CTX_set_quiet_shutdown(tm_ctx,1); if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL); SSL_CTX_set_cipher_list(tm_ctx,tm_cipher); if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file)) goto end; SSL_load_error_strings(); if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) || (!SSL_CTX_set_default_verify_paths(tm_ctx))) { /* BIO_printf(bio_err,"error setting default verify locations\n"); */ ERR_print_errors(bio_err); /* goto end; */ } if (tm_cipher == NULL) tm_cipher = getenv("SSL_CIPHER"); if (tm_cipher == NULL ) { fprintf( stderr, "No CIPHER specified\n" ); } if (!(perform & 1)) goto next; printf( "Collecting connection statistics for %d seconds\n", maxTime ); /* Loop and time how long it takes to make connections */ bytes_read=0; finishtime=(long)time(NULL)+maxTime; tm_Time_F(START); for (;;) { if (finishtime < (long)time(NULL)) break;#ifdef WIN32_STUFF if( flushWinMsgs(0) == -1 ) goto end; if( waitingToDie || exitNow ) /* we're dead */ goto end;#endif if( (scon = doConnection( NULL )) == NULL ) goto end; if (s_www_path != NULL) { BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) bytes_read+=i; }#ifdef NO_SHUTDOWN SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);#else SSL_shutdown(scon);#endif SHUTDOWN2(SSL_get_fd(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 */ i=(int)((long)time(NULL)-finishtime+maxTime); 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 %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); /* Now loop and time connections using the same session id over and over */next: if (!(perform & 2)) 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_www_path != NULL) { BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while (SSL_read(scon,buf,sizeof(buf)) > 0) ; }#ifdef NO_SHUTDOWN SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);#else SSL_shutdown(scon);#endif SHUTDOWN2(SSL_get_fd(scon)); nConn = 0; totalTime = 0.0; finishtime=(long)time(NULL)+maxTime; printf( "starting\n" ); bytes_read=0; tm_Time_F(START); for (;;) { if (finishtime < (long)time(NULL)) break;#ifdef WIN32_STUFF if( flushWinMsgs(0) == -1 ) goto end; if( waitingToDie || exitNow ) /* we're dead */ goto end;#endif if( (doConnection( scon )) == NULL ) goto end; if (s_www_path) { BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) bytes_read+=i; }#ifdef NO_SHUTDOWN SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);#else SSL_shutdown(scon);#endif SHUTDOWN2(SSL_get_fd(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 %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); ret=0;end: if (scon != NULL) SSL_free(scon); if (tm_ctx != NULL) { SSL_CTX_free(tm_ctx); tm_ctx=NULL; } apps_shutdown(); OPENSSL_EXIT(ret); }/*********************************************************************** * doConnection - make a connection * Args: * scon = earlier ssl connection for session id, or NULL * Returns: * SSL * = the connection pointer. */static SSL *doConnection(SSL *scon) { BIO *conn; SSL *serverCon; int width, i; fd_set readfds; if ((conn=BIO_new(BIO_s_connect())) == NULL) return(NULL);/* BIO_set_conn_port(conn,port);*/ BIO_set_conn_hostname(conn,host); if (scon == NULL) serverCon=SSL_new(tm_ctx); else { serverCon=scon; SSL_set_connect_state(serverCon); } SSL_set_bio(serverCon,conn,conn);#if 0 if( scon != NULL ) SSL_set_session(serverCon,SSL_get_session(scon));#endif /* ok, lets connect */ for(;;) { i=SSL_connect(serverCon); if (BIO_sock_should_retry(i)) { BIO_printf(bio_err,"DELAY\n"); i=SSL_get_fd(serverCon); width=i+1; FD_ZERO(&readfds); FD_SET(i,&readfds); /* Note: under VMS with SOCKETSHR the 2nd parameter * is currently of type (int *) whereas under other * systems it is (void *) if you don't have a cast it * will choke the compiler: if you do have a cast then * you can either go for (int *) or (void *). */ select(width,(void *)&readfds,NULL,NULL,NULL); continue; } break; } if(i <= 0) { BIO_printf(bio_err,"ERROR\n"); if (verify_error != X509_V_OK) BIO_printf(bio_err,"verify error:%s\n", X509_verify_cert_error_string(verify_error)); else ERR_print_errors(bio_err); if (scon == NULL) SSL_free(serverCon); return NULL; } return serverCon; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -