]> git.ipfire.org Git - fireperf.git/commitdiff
ctx: Move the context declaration into its own source file
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 19 Sep 2024 08:13:05 +0000 (08:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 19 Sep 2024 08:13:05 +0000 (08:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
12 files changed:
Makefile.am
src/client.c
src/client.h
src/ctx.c [new file with mode: 0644]
src/ctx.h [new file with mode: 0644]
src/logging.h
src/main.c
src/main.h
src/random.c
src/random.h
src/server.h
src/worker.h

index 16c30daeddd1bb9890dbf638cd4fdecdfb97a87b..f1ed7039394cef8cdcb602e53fc5fcafa6124783 100644 (file)
@@ -62,6 +62,8 @@ bin_PROGRAMS = \
 fireperf_SOURCES = \
        src/client.c \
        src/client.h \
+       src/ctx.c \
+       src/ctx.h \
        src/logging.c \
        src/logging.h \
        src/main.c \
index 5d7b6ae88ffb612c261807172030a58d2e9f253f..691c661ab3ce01b93dbc18b5dfd4c5970a184548 100644 (file)
@@ -26,6 +26,7 @@
 #include <unistd.h>
 
 #include "client.h"
+#include "ctx.h"
 #include "logging.h"
 #include "main.h"
 #include "random.h"
index b0a3f21bea4ce6a1cf26cec4871a55f67216f8ec..9ff4b76b457566a1d89e5dde1104b83ba4fdad99 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef FIREPERF_CLIENT_H
 #define FIREPERF_CLIENT_H
 
+#include "ctx.h"
 #include "main.h"
 
 int fireperf_client(struct fireperf_ctx* ctx, struct fireperf_stats* stats,
diff --git a/src/ctx.c b/src/ctx.c
new file mode 100644 (file)
index 0000000..ebf0b04
--- /dev/null
+++ b/src/ctx.c
@@ -0,0 +1,21 @@
+/*#############################################################################
+#                                                                             #
+# fireperf - A network benchmarking tool                                      #
+# Copyright (C) 2024 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include "ctx.h"
diff --git a/src/ctx.h b/src/ctx.h
new file mode 100644 (file)
index 0000000..e31ddad
--- /dev/null
+++ b/src/ctx.h
@@ -0,0 +1,59 @@
+/*#############################################################################
+#                                                                             #
+# fireperf - A network benchmarking tool                                      #
+# Copyright (C) 2024 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef FIREPERF_CTX_H
+#define FIREPERF_CTX_H
+
+#include <netinet/in.h>
+
+#define MAX_WORKERS 128
+
+// Forward declarations
+struct fireperf_random_pool;
+struct fireperf_worker;
+
+struct fireperf_ctx {
+       int terminated;
+       int loglevel;
+       enum {
+               FIREPERF_MODE_NONE = 0,
+               FIREPERF_MODE_CLIENT,
+               FIREPERF_MODE_SERVER,
+       } mode;
+       struct in6_addr address;
+       int duplex;
+       int keepalive_only;
+       int keepalive_count;
+       int keepalive_interval;
+       struct fireperf_random_pool* pool;
+       int port;
+       unsigned int listening_sockets;
+       unsigned long parallel;
+       unsigned int timeout;
+       int close;
+       int zero;
+
+       // Workers
+       struct fireperf_workers* workers[MAX_WORKERS];
+       unsigned int num_workers;
+       unsigned int max_workers;
+};
+
+#endif /* FIREPERF_CTX_H */
index 7e05f7e55afe688278becc481a91eb730b761d26..f7ee66193309ea2ded31bb20e4e23edba4401366 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <syslog.h>
 
-#include "main.h"
+#include "ctx.h"
 
 static inline void __attribute__((always_inline, format(printf, 2, 3)))
        fireperf_log_null(struct fireperf_ctx* ctx, const char* format, ...) {}
index 356989f795b7e19d4c22881241344f26d8d0405f..afe2c762c20ba8c54e25e70354fda0ccfbda3e65 100644 (file)
@@ -278,6 +278,9 @@ int main(int argc, char* argv[]) {
        // Initialise random number generator
        srandom(time(NULL));
 
+       // Fetch how many workers we would launch
+       ctx.max_workers = sysconf(_SC_NPROCESSORS_ONLN);
+
        // Set limits
        r = set_limits(&ctx);
        if (r)
index 215a58f940635803f4e80814149dc1a428debb30..ae779f31062f506188a3093c751035fde52c8985 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef FIREPERF_MAIN_H
 #define FIREPERF_MAIN_H
 
-#include <netinet/in.h>
 #include <time.h>
 
 #define DEFAULT_KEEPALIVE_COUNT     3
 
 #define EPOLL_MAX_EVENTS 128
 
-// Forward declaration
-struct fireperf_random_pool;
-
-struct fireperf_ctx {
-       int terminated;
-       int loglevel;
-       enum {
-               FIREPERF_MODE_NONE = 0,
-               FIREPERF_MODE_CLIENT,
-               FIREPERF_MODE_SERVER,
-       } mode;
-       struct in6_addr address;
-       int duplex;
-       int keepalive_only;
-       int keepalive_count;
-       int keepalive_interval;
-       struct fireperf_random_pool* pool;
-       int port;
-       unsigned int listening_sockets;
-       unsigned long parallel;
-       unsigned int timeout;
-       int close;
-       int zero;
-};
+#include "ctx.h"
 
 // Struct to collect statistics
 struct fireperf_stats {
index b263df9e88d1d10a785e05c04db00e2fbabd5648..86a99abee5e8f545b05663f1591cdba7f2a8dc52 100644 (file)
@@ -21,8 +21,8 @@
 #include <stdlib.h>
 #include <sys/random.h>
 
+#include "ctx.h"
 #include "logging.h"
-#include "main.h"
 #include "random.h"
 
 struct fireperf_random_pool* fireperf_random_pool_create(struct fireperf_ctx* ctx, size_t size) {
index 2aaa5a6989a2fa4e5c2e305bff59aa1f933e6e20..1fd89195b14ffc902a5403a47bcfa0bcd92421a8 100644 (file)
 #ifndef FIREPERF_RANDOM_H
 #define FIREPERF_RANDOM_H
 
-#include "main.h"
-
 struct fireperf_random_pool {
        char* data;
        size_t size;
 };
 
+#include "ctx.h"
+
 struct fireperf_random_pool* fireperf_random_pool_create(
        struct fireperf_ctx* ctx, size_t size);
 void fireperf_random_pool_free(struct fireperf_random_pool* pool);
index 77ab911d2c27d60917a3e4aad4a20b257d6a56cf..fb5f095012608de17ace13465adf8b9ca88c7598 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef FIREPERF_SERVER_H
 #define FIREPERF_SERVER_H
 
-#include "main.h"
+#include "ctx.h"
 
 int fireperf_server(struct fireperf_ctx* ctx, int epollfd, int timerfd);
 
index 4f3e74a4266ee12ed2c86a14e5bb325ad49787c6..7059df5c905af508efa2c3240b948075e6e69ee5 100644 (file)
@@ -23,7 +23,7 @@
 
 struct fireperf_worker;
 
-#include "main.h"
+#include "ctx.h"
 
 int fireperf_worker_create(struct fireperf_worker** worker, struct fireperf_ctx* ctx);
 void fireperf_worker_free(struct fireperf_worker* worker);