Add a delay option to load-tester socket
authorMartin Willi <martin@revosec.ch>
Fri, 19 Oct 2012 12:54:23 +0000 (14:54 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 29 Nov 2012 09:22:51 +0000 (10:22 +0100)
src/libcharon/plugins/load_tester/load_tester.c
src/libcharon/plugins/load_tester/load_tester_control.c

index fc41df7..f7361e6 100644 (file)
@@ -61,7 +61,7 @@ static FILE* make_connection()
 /**
  * Initiate load-tests
  */
-static int initiate(unsigned int count)
+static int initiate(unsigned int count, unsigned int delay)
 {
        FILE *stream;
        char c;
@@ -72,7 +72,7 @@ static int initiate(unsigned int count)
                return 1;
        }
 
-       fprintf(stream, "%u\n", count);
+       fprintf(stream, "%u %u\n", count, delay);
 
        while (1)
        {
@@ -94,11 +94,11 @@ static int initiate(unsigned int count)
 
 int main(int argc, char *argv[])
 {
-       if (argc == 3 && strcmp(argv[1], "initiate") == 0)
+       if (argc >= 3 && strcmp(argv[1], "initiate") == 0)
        {
-               return initiate(atoi(argv[2]));
+               return initiate(atoi(argv[2]), argc > 3 ? atoi(argv[3]) : 0);
        }
        fprintf(stderr, "Usage:\n");
-       fprintf(stderr, "  %s initiate <count>\n", argv[0]);
+       fprintf(stderr, "  %s initiate <count> [<delay in ms>]\n", argv[0]);
        return 1;
 }
index db2a313..0c21c23 100644 (file)
@@ -223,7 +223,7 @@ static job_requeue_t initiate(FILE *stream)
        enumerator_t *enumerator;
        peer_cfg_t *peer_cfg;
        child_cfg_t *child_cfg;
-       u_int i, count, failed = 0;
+       u_int i, count, failed = 0, delay = 0;
        char buf[16] = "";
 
        fflush(stream);
@@ -231,7 +231,7 @@ static job_requeue_t initiate(FILE *stream)
        {
                return JOB_REQUEUE_NONE;
        }
-       if (sscanf(buf, "%u", &count) != 1)
+       if (sscanf(buf, "%u %u", &count, &delay) < 1)
        {
                return JOB_REQUEUE_NONE;
        }
@@ -285,6 +285,10 @@ static job_requeue_t initiate(FILE *stream)
                                fprintf(stream, "!");
                                break;
                }
+               if (delay)
+               {
+                       usleep(delay * 1000);
+               }
                fflush(stream);
        }