#include <errno.h>
#include <signal.h>
-#include <sys/epoll.h>
#include <string.h>
+#include <sys/epoll.h>
+#include <sys/random.h>
#include <unistd.h>
#include "client.h"
return 0;
}
-static void randomize_buffer(char* buffer, size_t s) {
- return; // TODO
+/*
+ This is just an example implementation because getrandom() is too slow for
+ this purpose. I would need a really fast pseudo-RNG.
+*/
+static int randomize_buffer(char* buffer, size_t s) {
+ ssize_t r = getrandom(buffer, s, 0);
+
+ // Error
+ if (r < 0)
+ return 1;
+
+ // We received less data than we wanted
+ else if (r > 0 && (size_t)r < s)
+ return 1;
+
+ return 0;
}
static int send_data_to_server(struct fireperf_config* conf, int fd) {
// Randomize the buffer if requested, otherwise just send an empty buffer
if (!conf->zero) {
- randomize_buffer(buffer, sizeof(buffer));
+ int r = randomize_buffer(buffer, sizeof(buffer));
+ if (r) {
+ ERROR(conf, "Could not generate a random block of data: %s\n",
+ strerror(errno));
+ return 1;
+ }
}
do {