test-socket-signal: use frequency option
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 24 Oct 2010 09:22:51 +0000 (12:22 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 24 Oct 2010 09:23:34 +0000 (12:23 +0300)
Utils/test-socket-signal/peer.c

index 7b4e556..649660d 100644 (file)
@@ -4,6 +4,12 @@
  *    peer (client part)
  *
  * 2010, Razvan Deaconescu
+ *
+ * Sample run:
+ *   terminal 1 (leader):
+ *          ./peer -l -p 12345 -b 1024 -e 128 -f 10 localhost 54321
+ *   terminal 2 (follower):
+ *          ./peer -p 54321 -b 128 -e 1024 -f 1 localhost 12345
  */
 
 #include <stdio.h>
 
 #define RECEIVE_BUFFER_SIZE            65536
 
-#define TIMER_FREQUENCY_SECS           1
+/*
+ * TODO: fix nomenclature (TIMER_BASE_PERIOD, cmd_args.frequency)
+ * run the timer once each TIMER_BASE_PERIOD
+ * this is divided by cmd_args.frequency for a shorter period
+ */
+
+#define TIMER_BASE_PERIOD              1
 #define CLOCKID                                CLOCK_REALTIME
 #define SIG                            SIGRTMIN
 
@@ -175,10 +187,11 @@ static void schedule_timer(void)
        DIE(rc < 0, "timer_create");
 
        /* Start the timer */
-       its.it_value.tv_sec = TIMER_FREQUENCY_SECS;
-       its.it_value.tv_nsec = 0;
-       its.it_interval.tv_sec = TIMER_FREQUENCY_SECS;
-       its.it_interval.tv_nsec = 0;
+       /* TODO: store nanosecs in a specialized variable for sane code */
+       its.it_value.tv_sec = TIMER_BASE_PERIOD / cmd_args.frequency;
+       its.it_value.tv_nsec = (TIMER_BASE_PERIOD % cmd_args.frequency) * (1000000000 / cmd_args.frequency);
+       its.it_interval.tv_sec = TIMER_BASE_PERIOD / cmd_args.frequency;
+       its.it_interval.tv_nsec = (TIMER_BASE_PERIOD % cmd_args.frequency) * (1000000000 / cmd_args.frequency);
        rc = timer_settime(timerid, 0, &its, NULL);
        DIE(rc < 0, "timer_settime");