commit 44033f3d48780e76d067c5dd852dfce31004c598
parent b0d7e859556751c043494be4ca63ded24c8e72fa
Author: Yersa Nordman <yersa@finwo.nl>
Date: Thu, 26 Oct 2023 21:06:45 +0200
Added a method for shutting down fnet_main
Diffstat:
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/fnet.c b/src/fnet.c
@@ -1,4 +1,5 @@
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -42,6 +43,7 @@ struct fnet_internal_t {
struct fnet_internal_t *connections = NULL;
EPOLL_HANDLE epfd = 0;
+bool keepRunning = true;
FNET_RETURNCODE setkeepalive(FNET_SOCKET fd) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &(int){1}, sizeof(int))) {
@@ -704,7 +706,7 @@ FNET_RETURNCODE fnet_main() {
struct epoll_event events[8];
- while(1) {
+ while(keepRunning) {
// Do the actual processing
if (epfd) {
@@ -741,3 +743,8 @@ FNET_RETURNCODE fnet_main() {
// TODO: is this really ok?
return FNET_RETURNCODE_OK;
}
+
+FNET_RETURNCODE fnet_shutdown() {
+ keepRunning = false;
+ return FNET_RETURNCODE_OK;
+}
diff --git a/src/fnet.h b/src/fnet.h
@@ -77,5 +77,6 @@ FNET_RETURNCODE fnet_free(struct fnet_t *connection);
FNET_RETURNCODE fnet_tick();
FNET_RETURNCODE fnet_main();
+FNET_RETURNCODE fnet_shutdown();
#endif // __INCLUDE_FINWO_FNET_H__