commit dc98732ebfa2ab0584b648e8ba499617255b3f60
parent 126ed72ff669709239846e1c92223e77c8b8f2c1
Author: Yersa Nordman <yersa@finwo.nl>
Date: Tue, 24 Oct 2023 21:44:33 +0200
Added a way to stop fnet
Diffstat:
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/fnet.c b/src/fnet.c
@@ -30,6 +30,8 @@
#define FNET_SOCKET int
#endif
+int fnet_keepRunning = 1;
+
struct fnet_internal_t {
struct fnet_t ext; // KEEP AT TOP, allows casting between fnet_internal_t* and fnet_t*
void *prev;
@@ -704,7 +706,7 @@ FNET_RETURNCODE fnet_main() {
struct epoll_event events[8];
- while(1) {
+ while(fnet_keepRunning) {
// Do the actual processing
if (epfd) {
diff --git a/src/fnet.h b/src/fnet.h
@@ -38,6 +38,8 @@
#define FNET_CALLBACK(NAME) void (*(NAME))(struct fnet_ev *event)
+extern int fnet_keepRunning;
+
struct fnet_ev {
struct fnet_t *connection;
FNET_EVENT type;
diff --git a/test.c b/test.c
@@ -11,6 +11,8 @@
#include "fnet.h"
+int ticked = 0;
+
void onClose(struct fnet_ev *ev) {
printf("Connection closed!\n");
}
@@ -35,6 +37,13 @@ void onTick(struct fnet_ev *ev) {
char *data = "Hello world!";
int cnt = *((int*)ev->udata);
+ // Limit to 4
+ ticked++;
+ if (ticked > 4) {
+ fnet_keepRunning = 0;
+ return;
+ }
+
fnet_write(ev->connection, &((struct buf){
.len = strlen(data) + 1,
.data = data,