diff options
| author | iceyrazor <iceyrazor@mailfence.com> | 2026-10-11 00:21:32 -0500 |
|---|---|---|
| committer | iceyrazor <iceyrazor@mailfence.com> | 2026-10-11 00:21:32 -0500 |
| commit | a926ae205ecb42a603e428346cf99dc1e66ed691 (patch) | |
| tree | 9d207cf8f84dc1d9e48b541f0a18309f7f96c442 /Server.h | |
| parent | 3521cc6e1a87f16c8db5c3c5a0c3cf59e1ff04cb (diff) | |
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
Diffstat (limited to 'Server.h')
| -rwxr-xr-x | Server.h | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -5,6 +5,7 @@ #include <netinet/in.h> #include <stdbool.h> #include <pthread.h> +#include <stdatomic.h> 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 */ |
