--- /dev/null
+/*#############################################################################
+# #
+# 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 <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <sys/epoll.h>
+#include <unistd.h>
+
+#include "main.h"
+#include "logging.h"
+#include "worker.h"
+
+struct fireperf_worker {
+ pthread_t thread;
+
+ // Configuration
+ struct fireperf_config* conf;
+
+ // Epoll
+ int epollfd;
+};
+
+static void fireperf_worker_free(struct fireperf_worker* worker) {
+ if (worker->epollfd >= 0)
+ close(worker->epollfd);
+
+ free(worker);
+}
+
+int fireperf_worker_create(struct fireperf_worker** worker, struct fireperf_config* conf) {
+ struct fireperf_worker* w = NULL;
+ int r;
+
+ // Allocate a new worker
+ w = calloc(1, sizeof(*w));
+ if (!w)
+ return -errno;
+
+ // Reference the configuration
+ w->conf = conf;
+
+ // Create a new event loop
+ w->epollfd = epoll_create1(0);
+ if (w->epollfd < 0) {
+ ERROR(conf, "Could not create event loop: %m\n");
+ r = -errno;
+ goto ERROR;
+ }
+
+ DEBUG(conf, "Created a new worker\n");
+
+ // Return the worker
+ *worker = w;
+
+ return 0;
+
+ERROR:
+ if (w)
+ fireperf_worker_free(w);
+
+ return r;
+}
+
+/*
+ The main function of the worker.
+*/
+static void* fireperf_worker_main(void* w) {
+ struct fireperf_worker* worker = w;
+
+ DEBUG(worker->conf, "New worker launched as %lu\n", pthread_self());
+
+ return 0;
+}
+
+int fireperf_worker_launch(struct fireperf_worker* worker) {
+ int r;
+
+ // Launch the worker
+ r = pthread_create(&worker->thread, NULL, fireperf_worker_main, worker);
+ if (r) {
+ ERROR(worker->conf, "Could not launch the worker: %m\n");
+ }
+
+ return r;
+}
+
+int fireperf_worker_is_alive(struct fireperf_worker* worker) {
+ return pthread_tryjoin_np(worker->thread, NULL);
+}
--- /dev/null
+/*#############################################################################
+# #
+# 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_WORKER_H
+#define FIREPERF_WORKER_H
+
+struct fireperf_worker;
+
+#include "main.h"
+
+int fireperf_worker_create(struct fireperf_worker** worker, struct fireperf_config* conf);
+
+int fireperf_worker_launch(struct fireperf_worker* worker);
+int fireperf_worker_is_alive(struct fireperf_worker* worker);
+
+#endif /* FIREPERF_WORKER_H */