set excange message to 128 characters
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 6 Oct 2025 09:28:49 +0000 (11:28 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 6 Oct 2025 09:28:49 +0000 (11:28 +0200)
mq_lat.c
mq_rtt.c
pipe_lat.c
pipe_rtt.c
udp_lat.c
udp_rtt.c

index 15aa7b23ca4d68bc1587e8ff6264bb78dda8293c..63b1145769d87876b4d11ed75479a35785552ad4 100644 (file)
--- a/mq_lat.c
+++ b/mq_lat.c
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lpthread -lrt */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -13,6 +13,7 @@
 #include <pthread.h>
 #include <unistd.h>
 
+#include "msg.h"
 #include "mtime.h"
 #include "test.h"
 
@@ -25,6 +26,7 @@ char *message = "Message queue latency";
 void (*usage_ext) (FILE *) = NULL;
 int (*parse_arg_ext) (char *) = NULL;
 
+#define MSGLEN 128
 #define MAXBUF 1024
 #define TIMER 1000
 
@@ -64,8 +66,8 @@ void *ping (__attribute__((unused)) void *arg)
         pthread_mutex_unlock (&mutex);
 
         sys_timestamp (&ts1);
-        char *buffer = "ping";
-        if (mq_send (mq, buffer, strlen (buffer) + 1, 0) == -1) {
+        char *msg = get_msg (MSGLEN);
+        if (mq_send (mq, msg, MSGLEN, 0) == -1) {
             fprintf (stderr, "ping error: mq_send (%d)\n", try);
             rc = 1;
             pthread_exit (NULL);
index d387063c369e21e6e77a0612ee73fdb6e461d588..5f4ad41e2adcc85b6e1c6abddeaa1ded549f434b 100644 (file)
--- a/mq_rtt.c
+++ b/mq_rtt.c
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lrt */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -14,6 +14,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
+#include "msg.h"
 #include "mtime.h"
 #include "test.h"
 
@@ -26,6 +27,7 @@ char *message = "Message queue RTT";
 void (*usage_ext) (FILE *) = NULL;
 int (*parse_arg_ext) (char *) = NULL;
 
+#define MSGLEN 128
 #define MAXBUF 1024
 
 int ping (mqd_t mq)
@@ -34,19 +36,19 @@ int ping (mqd_t mq)
     printf ("Sending ping...\n");
     for (int i = 0; i < nb_measurements; i++) {
 
+        char *msg = get_msg (MSGLEN);
         char buffer[MAXBUF] = { 0 };
-        sprintf (buffer, "ping %d", i);
 
         ts_t ts1;
         sys_timestamp (&ts1);
 
-        if (mq_send (mq, buffer, strlen (buffer) + 1, 0) == -1) {
+        if (mq_send (mq, msg, MSGLEN, 0) == -1) {
             fprintf (stderr, "ping error: mq_send (%d)\n", i);
             return 1;
         }
         //printf ("send '%s'\n", buffer);
 
-        if (mq_receive (mq, buffer, sizeof(buffer), NULL) == -1) {
+        if (mq_receive (mq, buffer, sizeof(buffer) - 1, NULL) == -1) {
             fprintf (stderr, "ping error: mq_receive (%d)\n", i);
             return 1;
         }
@@ -66,15 +68,16 @@ int pong (mqd_t mq)
     printf ("Responding pong...\n");
     for (int i = 0; i < nb_measurements; i++) {
 
+        char *msg = get_msg (MSGLEN);
         char buffer[MAXBUF] = { 0 };
 
-        if (mq_receive (mq, buffer, sizeof(buffer), NULL) == -1) {
+        if (mq_receive (mq, buffer, sizeof(buffer) - 1, NULL) == -1) {
             fprintf (stderr, "pong error: mq_receive (%d)\n", i);
             return 1;
         }
         //printf ("receive '%s'\n", buffer);
 
-        if (mq_send (mq, buffer, strlen (buffer) + 1, 0) == -1) {
+        if (mq_send (mq, msg, MSGLEN, 0) == -1) {
             fprintf (stderr, "pong error: mq_send (%d)\n", i);
             return 1;
         }
index b4137b15d7c298f63b05e7fbe2cc3b7418e358b6..b30397be4551beb627ca7c421747d0410925acd6 100644 (file)
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lpthread -lrt */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -9,6 +9,7 @@
 #include <pthread.h>
 #include <unistd.h>
 
+#include "msg.h"
 #include "mtime.h"
 #include "test.h"
 
@@ -21,6 +22,7 @@ char *message = "Pipe latency";
 void (*usage_ext) (FILE *) = NULL;
 int (*parse_arg_ext) (char *) = NULL;
 
+#define MSGLEN 128
 #define MAXBUF 1024
 #define TIMER 100
 
@@ -44,14 +46,13 @@ void *ping (__attribute__((unused)) void *arg)
 
     for (int i = 0; i < nb_measurements; i++) {
 
-        char buffer[MAXBUF] = { 0 };
-        sprintf (buffer, "ping %d", i);
+        char *msg = get_msg (MSGLEN);
 
         pthread_mutex_lock (&mutex);
         pthread_mutex_unlock (&mutex);
 
         sys_timestamp (&ts1);
-        if (write (fdout, buffer, strlen (buffer) + 1) == -1) {
+        if (write (fdout, msg, MSGLEN) == -1) {
             fprintf (stderr, "ping error: write (%d)\n", i);
             rc = 1;
             pthread_exit (NULL);
index 30a76796bd66a7266a5abac7963e473618970cf7..29a365d0020411941dd6059d8e91755216deec3a 100644 (file)
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lrt */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -10,6 +10,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
+#include "msg.h"
 #include "mtime.h"
 #include "test.h"
 
@@ -22,6 +23,7 @@ char *message = "Pipe RTT";
 void (*usage_ext) (FILE *) = NULL;
 int (*parse_arg_ext) (char *) = NULL;
 
+#define MSGLEN 128
 #define MAXBUF 1024
 
 int ping (int fdin, int fdout)
@@ -30,19 +32,19 @@ int ping (int fdin, int fdout)
     printf ("Sending ping...\n");
     for (int i = 0; i < nb_measurements; i++) {
 
+        char *msg = get_msg (MSGLEN);
         char buffer[MAXBUF] = { 0 };
-        sprintf (buffer, "ping %d", i);
 
         ts_t ts1;
         sys_timestamp (&ts1);
 
-        if (write (fdout, buffer, strlen (buffer) + 1) == -1) {
+        if (write (fdout, msg, MSGLEN) == -1) {
             fprintf (stderr, "ping error: write (%d)\n", i);
             return 1;
         }
         //printf ("write '%s'\n", buffer);
 
-        if (read (fdin, buffer, sizeof(buffer)) == -1) {
+        if (read (fdin, buffer, sizeof(buffer) - 1) == -1) {
             fprintf (stderr, "ping error: read (%d)\n", i);
             return 1;
         }
@@ -62,15 +64,16 @@ int pong (int fdin, int fdout)
     printf ("Responding pong...\n");
     for (int i = 0; i < nb_measurements; i++) {
 
+        char *msg = get_msg (MSGLEN);
         char buffer[MAXBUF] = { 0 };
 
-        if (read (fdin, buffer, sizeof(buffer)) == -1) {
+        if (read (fdin, buffer, sizeof(buffer) - 1) == -1) {
             fprintf (stderr, "ping error: read (%d)\n", i);
             return 1;
         }
         //printf ("read '%s'\n", buffer);
 
-        if (write (fdout, buffer, strlen (buffer) + 1) == -1) {
+        if (write (fdout, msg, MSGLEN) == -1) {
             fprintf (stderr, "ping error: write (%d)\n", i);
             return 1;
         }
index 2d7c7440e7531b0a7d2794b46f8bfad4fee70330..ab7499e639456a7f94ba7ab1b590b03557d56d33 100644 (file)
--- a/udp_lat.c
+++ b/udp_lat.c
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lpthread -lrt */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -13,6 +13,7 @@
 #include <arpa/inet.h>
 #include <sys/socket.h>
 
+#include "msg.h"
 #include "mtime.h"
 #include "test.h"
 
@@ -47,6 +48,7 @@ int _parse_arg_ext (char *arg)
 }
 int (*parse_arg_ext) (char *) = _parse_arg_ext;
 
+#define MSGLEN 128
 #define MAXBUF 1024
 #define TIMER 1000
 
@@ -88,14 +90,13 @@ void *ping (__attribute__((unused)) void *arg)
 
     for (int i = 0; i < nb_measurements; i++) {
 
-        char buffer[MAXBUF] = { 0 };
-        sprintf (buffer, "ping %d", i);
+        char *msg = get_msg (MSGLEN);
 
         pthread_mutex_lock (&mutex);
         pthread_mutex_unlock (&mutex);
 
         sys_timestamp (&ts1);
-        if (sendto (sock, buffer, strlen (buffer) + 1, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
+        if (sendto (sock, msg, MSGLEN, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
             fprintf (stderr, "ping error: sendto (%d)\n", i);
             rc = 1;
             pthread_exit (NULL);
index de97b8535067358f0b3daac4b5bb0e4713a6e172..cbb545c7372caadd34d3dcc735660114bce8ac29 100644 (file)
--- a/udp_rtt.c
+++ b/udp_rtt.c
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lrt */
+/* linker: msg.o mtime.o test.o stat.o -lm -lrt */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -14,6 +14,7 @@
 #include <arpa/inet.h>
 #include <sys/socket.h>
 
+#include "msg.h"
 #include "mtime.h"
 #include "test.h"
 
@@ -60,6 +61,7 @@ int _parse_arg_ext (char *arg)
 }
 int (*parse_arg_ext) (char *) = _parse_arg_ext;
 
+#define MSGLEN 128
 #define MAXBUF 1024
 
 int ping (int local_port, int remote_addr, int remote_port)
@@ -89,19 +91,19 @@ int ping (int local_port, int remote_addr, int remote_port)
     printf ("Sending ping...\n");
     for (int i = 0; i < nb_measurements; i++) {
 
+        char *msg = get_msg (MSGLEN);
         char buffer[MAXBUF] = { 0 };
-        sprintf (buffer, "ping %d", i);
 
         ts_t ts1;
         sys_timestamp (&ts1);
 
-        if (sendto (sock, buffer, strlen (buffer) + 1, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
+        if (sendto (sock, msg, MSGLEN, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
             fprintf (stderr, "ping error: sendto (%d)\n", i);
             return 1;
         }
         //printf ("sendto '%s'\n", buffer);
 
-        int len = recv (sock, buffer, MAXBUF, 0);
+        int len = recv (sock, buffer, sizeof (buffer) - 1, 0);
         if (len == -1) {
             fprintf (stderr, "ping error: recv_from (%d)\n", i);
             return 1;
@@ -145,16 +147,17 @@ int pong (int local_port, int remote_addr, int remote_port)
     printf ("Sending pong...\n");
     for (int i = 0; i < nb_measurements; i++) {
 
+        char *msg = get_msg (MSGLEN);
         char buffer[MAXBUF] = { 0 };
 
-        int len = recv (sock, buffer, MAXBUF, 0);
+        int len = recv (sock, buffer, sizeof (buffer) - 1, 0);
         if (len == -1) {
             fprintf (stderr, "pong error: recv_from (%d)\n", i);
             return 1;
         }
         //printf ("recv_from '%s'\n", buffer);
 
-        if (sendto (sock, buffer, len, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
+        if (sendto (sock, msg, MSGLEN, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) {
             fprintf (stderr, "pong error: sendto (%d)\n", i);
             return 1;
         }