--- apps/s_server.c	2012-12-30 21:00:33.000000000 +0400
+++ apps/s_server.c.patched	2013-01-09 02:56:51.000000000 +0400
@@ -282,6 +282,9 @@ static SSL_CTX *ctx=NULL;
 static SSL_CTX *ctx2=NULL;
 #endif
 static int www=0;
+static int show_transfer_rate=0;
+static int connections_maximum=0;
+static int connections_count=0;
 
 static BIO *bio_s_out=NULL;
 static BIO *bio_s_msg = NULL;
@@ -568,6 +571,9 @@ static void sv_usage(void)
 #endif
 	BIO_printf(bio_err," -keymatexport label   - Export keying material using label\n");
 	BIO_printf(bio_err," -keymatexportlen len  - Export len bytes of keying material (default 20)\n");
+	BIO_printf(bio_err," -max_connections num  - Exit after performing <num> connections\n");
+	BIO_printf(bio_err," -show_transfer_rate   - Show each connection duration and transfer rate.\n");
+	BIO_printf(bio_err,"                         Data transfer rate only make sence with -WWW or -HTTP.\n");
 	}
 
 static int local_argc=0;
@@ -1391,6 +1397,20 @@ int MAIN(int argc, char *argv[])
 			keymatexportlen=atoi(*(++argv));
 			if (keymatexportlen == 0) goto bad;
 			}
+		else if (strcmp(*argv,"-max_connections") == 0)
+			{
+			if (--argc < 1) goto bad;
+			connections_maximum = atol(*(++argv));
+			if (connections_maximum <= 0) {
+                            printf("-max_connections argument should be positive integer >0");
+                            goto bad;
+                        }
+                        printf("Maximum connections limit: %u\n", connections_maximum);
+			}
+		else if (strcmp(*argv,"-show_transfer_rate") == 0)
+			{
+			show_transfer_rate = 1;
+			}
 		else
 			{
 			BIO_printf(bio_err,"unknown option %s\n",*argv);
@@ -2743,6 +2763,10 @@ static int www_body(char *hostname, int 
 		SSL_set_msg_callback_arg(con, bio_s_msg ? bio_s_msg : bio_s_out);
 		}
 
+	struct timeval tim;
+	double time_start = 0.0;
+	unsigned long data_transfered = 0;
+
 	for (;;)
 		{
 		if (hack)
@@ -2898,7 +2922,15 @@ static int www_body(char *hostname, int 
 		else if ((www == 2 || www == 3)
                          && (strncmp("GET /",buf,5) == 0))
 			{
-			BIO *file;
+
+            if(show_transfer_rate){
+                gettimeofday(&tim, NULL);
+                time_start = tim.tv_sec+(tim.tv_usec/1000000.0);
+                if(!s_quiet)
+                    printf("Transfer rate measure START\n");
+            }
+
+            BIO *file;
 			char *p,*e;
 			static const char *text="HTTP/1.0 200 ok\r\nContent-type: text/plain\r\n\r\n";
 
@@ -2993,6 +3025,7 @@ static int www_body(char *hostname, int 
 			for (;;)
 				{
 				i=BIO_read(file,buf,bufsize);
+				data_transfered += i;
 				if (i <= 0) break;
 
 #ifdef RENEG
@@ -3045,6 +3078,17 @@ write_error:
 			break;
 		}
 end:
+    
+    if(show_transfer_rate && time_start > 0){
+        gettimeofday(&tim, NULL);
+        double time_end = tim.tv_sec + (tim.tv_usec/1000000.0);
+        double duration = time_end - time_start;
+        double rate = data_transfered/duration/1024.0;
+        printf("Data transfer took %.5lf seconds.\n", duration);
+        printf("Data transfered %.2lf Kb.\n", data_transfered/1024.0);
+        printf("Data transfer rate is %.2lf Kb/sec\n", rate);
+    }
+
 #if 1
 	/* make sure we re-use sessions */
 	SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
@@ -3056,6 +3100,15 @@ end:
 
 err:
 
+        ++connections_count;
+        if(!s_quiet && connections_maximum)
+            printf("Performed %d connection(s) out of %d.\n", connections_count, connections_maximum);
+        if(connections_maximum && connections_count >= connections_maximum){
+                if(!s_quiet)
+                    printf("Finish.\n");
+                ret = -1; /* Just exit. */
+        }
+
 	if (ret >= 0)
 		BIO_printf(bio_s_out,"ACCEPT\n");
 
