#include "main.h"
#include "util.h"
-// Struct to collect client statistics
-struct fireperf_client_stats {
- struct timespec last_printed;
-
- // Total number of open connections
- unsigned int open_connections;
-
- // New connections
- unsigned int connections;
-
- size_t bytes_sent;
- size_t total_bytes_sent;
-};
-
// Set to one when the timeout has expired
static int timeout_expired = 0;
return pool->data + offset;
}
-static int dump_stats(struct fireperf_config* conf, struct fireperf_client_stats* stats) {
+static int dump_stats(struct fireperf_config* conf, struct fireperf_stats* stats) {
struct timespec now;
// Fetch the time
}
static int send_data_to_server(struct fireperf_config* conf,
- struct fireperf_client_stats* stats, int fd, struct fireperf_random_pool* pool) {
+ struct fireperf_stats* stats, int fd, struct fireperf_random_pool* pool) {
const char* buffer = ZERO;
ssize_t bytes_sent;
return 0;
}
-int fireperf_client(struct fireperf_config* conf, int epollfd, int timerfd) {
- struct fireperf_client_stats stats = { 0 };
+int fireperf_client(struct fireperf_config* conf, struct fireperf_stats* stats,
+ int epollfd, int timerfd) {
struct fireperf_random_pool* pool = NULL;
DEBUG(conf, "Launching " PACKAGE_NAME " in client mode\n");
while (!conf->terminated && !timeout_expired) {
// Open connections
- while (stats.open_connections < conf->parallel) {
+ while (stats->open_connections < conf->parallel) {
int fd = open_connection(conf);
if (fd < 0)
continue;
goto ERROR;
}
- stats.open_connections++;
- stats.connections++;
+ stats->open_connections++;
+ stats->connections++;
}
int fds = epoll_wait(epollfd, events, EPOLL_MAX_EVENTS, -1);
goto ERROR;
}
- r = dump_stats(conf, &stats);
+ r = dump_stats(conf, stats);
if (r)
goto ERROR;
close(fd);
- stats.open_connections--;
+ stats->open_connections--;
} else if (events[i].events & EPOLLOUT) {
- r = send_data_to_server(conf, &stats, fd, pool);
+ r = send_data_to_server(conf, stats, fd, pool);
if (r)
goto ERROR;
}
#include "main.h"
-int fireperf_client(struct fireperf_config* conf, int epollfd, int timerfd);
+int fireperf_client(struct fireperf_config* conf, struct fireperf_stats* stats,
+ int epollfd, int timerfd);
#endif /* FIREPERF_CLIENT_H */
.parallel = DEFAULT_PARALLEL,
.timeout = DEFAULT_TIMEOUT,
};
+ struct fireperf_stats stats = { 0 };
int r;
// Parse command line
switch (conf.mode) {
case FIREPERF_MODE_CLIENT:
- return fireperf_client(&conf, epollfd, timerfd);
+ return fireperf_client(&conf, &stats, epollfd, timerfd);
case FIREPERF_MODE_SERVER:
- return fireperf_server(&conf, epollfd, timerfd);
+ return fireperf_server(&conf, &stats, epollfd, timerfd);
case FIREPERF_MODE_NONE:
fprintf(stderr, "No mode selected\n");
#define FIREPERF_MAIN_H
#include <netinet/in.h>
+#include <time.h>
#define DEFAULT_KEEPALIVE_COUNT 3
#define DEFAULT_KEEPALIVE_INTERVAL 10
int zero;
};
+// Struct to collect statistics
+struct fireperf_stats {
+ struct timespec last_printed;
+
+ // Total number of open connections
+ unsigned int open_connections;
+
+ // New connections
+ unsigned int connections;
+
+ // Total transferred data
+ size_t bytes_received;
+ size_t total_bytes_received;
+ size_t bytes_sent;
+ size_t total_bytes_sent;
+};
+
#endif /* FIREPERF_MAIN_H */
#define SOCKET_BACKLOG 1024
-// Struct to collect server statistics
-struct fireperf_server_stats {
- struct timespec last_printed;
-
- // Total number of open connections
- unsigned int open_connections;
-
- // New connections
- unsigned int connections;
-
- size_t bytes_received;
- size_t total_bytes_received;
-};
-
-static int dump_stats(struct fireperf_config* conf, struct fireperf_server_stats* stats) {
+static int dump_stats(struct fireperf_config* conf, struct fireperf_stats* stats) {
struct timespec now;
// Fetch the time
}
static int handle_io_on_connection(struct fireperf_config* conf,
- struct fireperf_server_stats* stats, int fd) {
+ struct fireperf_stats* stats, int fd) {
char buffer[SOCKET_RECV_BUFFER_SIZE];
ssize_t bytes_read;
return 0;
}
-int fireperf_server(struct fireperf_config* conf, int epollfd, int timerfd) {
- struct fireperf_server_stats stats = { 0 };
-
+int fireperf_server(struct fireperf_config* conf, struct fireperf_stats* stats,
+ int epollfd, int timerfd) {
DEBUG(conf, "Launching " PACKAGE_NAME " in server mode\n");
int listening_sockets[conf->listening_sockets];
}
// A connection has been opened
- stats.open_connections++;
- stats.connections++;
+ stats->open_connections++;
+ stats->connections++;
// Handle timer events
} else if (fd == timerfd) {
goto ERROR;
}
- r = dump_stats(conf, &stats);
+ r = dump_stats(conf, stats);
if (r)
goto ERROR;
close(fd);
// This connection is now closed
- stats.open_connections--;
+ stats->open_connections--;
// Skip processing anything else, because it would be pointless
continue;
// One of the connections had IO
if (events[i].events & EPOLLIN) {
- r = handle_io_on_connection(conf, &stats, fd);
+ r = handle_io_on_connection(conf, stats, fd);
if (r < 0)
goto ERROR;
}
#include "main.h"
-int fireperf_server(struct fireperf_config* conf, int epollfd, int timerfd);
+int fireperf_server(struct fireperf_config* conf, struct fireperf_stats* stats,
+ int epollfd, int timerfd);
#endif /* FIREPERF_SERVER_H */