From a926ae205ecb42a603e428346cf99dc1e66ed691 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Sun, 11 Oct 2026 00:21:32 -0500 Subject: major refactor: Some Thread Safety - removed web. silly to have that in a socket library - made shared changing variables atomic - added mutex locking to some things - removed requirement for iceys-c-libs (that was a web thing) - removed launch variable - check if on_message is actually defined - init on_message and on_disconnect NULL --- Server.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'Server.h') diff --git a/Server.h b/Server.h index 0a55543..241351a 100755 --- a/Server.h +++ b/Server.h @@ -5,6 +5,7 @@ #include #include #include +#include struct AcceptedSocket{ int socketFD; @@ -12,7 +13,7 @@ struct AcceptedSocket{ int error; bool succ; pthread_t thread_id; - bool shutdown; + atomic_bool shutdown; struct AcceptedSocket *next; }; @@ -24,25 +25,22 @@ struct Server{ u_long interface; int port; int backlog; - bool running; + atomic_bool running; + + pthread_t server_thread_id; + pthread_t cleanup_thread_id; struct sockaddr_in address; int socket; - char *html_folder; + pthread_mutex_t list_lock; struct AcceptedSocket *accepted_socket; - pthread_t (*launch)(struct Server *server); void (*on_message)(struct Server *server, char message[], ssize_t amountRecv, int socketFD); void (*on_disconnect)(struct Server *server, int socketFD); }; -/* - * AF_INET, SOCK_STREAM, 0, INADDR_ANY, port, 10, launch_socket - * or - * AF_INET, SOCK_STREAM, 0, INADDR_ANY, port, 10, launch - */ -struct Server server_constructor(int domain, int service, int protocol, u_long interface, int port, int backlog, pthread_t (*launch)(struct Server *server)); +struct Server server_constructor(int domain, int service, int protocol, u_long interface, int port, int backlog); #endif /* Server_h */ -- cgit v1.3