fnet.c

Simple C networking library
git clone git://git.finwo.net/lib/fnet.c
Log | Files | Refs | README

commit a69823f7fcdaf0b301d2c7ac703b07658d5024cf
parent 44033f3d48780e76d067c5dd852dfce31004c598
Author: Yersa Nordman <yersa@finwo.nl>
Date:   Thu, 26 Oct 2023 21:24:20 +0200

Keep virtual count of runners instead of keepRunning

Diffstat:
Msrc/fnet.c | 13+++++++++----
Msrc/fnet.h | 1+
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/fnet.c b/src/fnet.c @@ -43,7 +43,7 @@ struct fnet_internal_t { struct fnet_internal_t *connections = NULL; EPOLL_HANDLE epfd = 0; -bool keepRunning = true; +int runners = 0; FNET_RETURNCODE setkeepalive(FNET_SOCKET fd) { if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &(int){1}, sizeof(int))) { @@ -704,9 +704,15 @@ FNET_RETURNCODE fnet_main() { int ev_count; int i; + if (runners) { + return FNET_RETURNCODE_ALREADY_ACTIVE; + } + + runners++; + struct epoll_event events[8]; - while(keepRunning) { + while(runners) { // Do the actual processing if (epfd) { @@ -740,11 +746,10 @@ FNET_RETURNCODE fnet_main() { } - // TODO: is this really ok? return FNET_RETURNCODE_OK; } FNET_RETURNCODE fnet_shutdown() { - keepRunning = false; + runners = 0; return FNET_RETURNCODE_OK; } diff --git a/src/fnet.h b/src/fnet.h @@ -18,6 +18,7 @@ #define FNET_RETURNCODE_NOT_IMPLEMENTED -3 #define FNET_RETURNCODE_ERRNO -4 #define FNET_RETURNCODE_UNPROCESSABLE -5 +#define FNET_RETURNCODE_ALREADY_ACTIVE -6 #define FNET_STATUS uint8_t #define FNET_STATUS_INITIALIZING 0