aboutsummaryrefslogtreecommitdiffstats
path: root/server/main.c
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov2070@gmail.com>2024-07-04 20:49:53 +0300
committerjustanothercatgirl <sotov@twistea.su>2025-02-02 19:09:51 +0300
commit3eeee14d5d5c93ae3d156aabae5a96d1c09f185a (patch)
treef23794a428cf663498cff01a148a3f398d42f120 /server/main.c
parent0cd383b2c444936dc2290c850c02a0cae11187cd (diff)
Renamed types, migrated to make, changed directory hierarchy
Diffstat (limited to 'server/main.c')
-rw-r--r--server/main.c62
1 files changed, 16 insertions, 46 deletions
diff --git a/server/main.c b/server/main.c
index f899f7e..b6745e0 100644
--- a/server/main.c
+++ b/server/main.c
@@ -1,62 +1,32 @@
-#include <netinet/in.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <stdio.h>
-
+#include <bits/types/sigset_t.h>
#define CONTAINER_IMPLEMENTATION
+#define HSET_MAX_BUCKET_SIZE 4
#include <container.h>
#undef CONTAINER_IMPLEMENTATION
-#include "channel.h"
-
-#define MAIN_PORT 8164
+#include "tcp.h"
-enum request_type {
- spawn_channel,
- get_channels,
-};
+#include <signal.h>
-static int* open_sockets;
-static int request_socket;
+#define MAIN_PORT 8164
-void init(void) {
- open_sockets = array_new(int, 0);
- request_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- struct sockaddr_in addr = {.sin_family = AF_INET, .sin_port = htons(MAIN_PORT), .sin_addr = {INADDR_ANY}};
-
- for (int retries = 0; retries <= 5; ++retries) {
- if (bind(request_socket, (struct sockaddr*)&addr, sizeof(addr)) == 0) break;
- else {
- perror("init (bind)");
- sleep(1);
- }
+void setup_signal(void) {
+ struct sigaction signal = {.sa_handler = print_state, .sa_mask = {{0}}, .sa_flags = 0};
+ if (sigaction(SIGUSR1, &signal, NULL) != 0) {
+ WHERE;
+ exit(EXIT_FAILURE);
}
-}
-
-enum request_type wait_for_requests(void) {
- return spawn_channel;
-}
-
-int spawn_channel_thread(void) {
- return 0;
-}
-
-void event_loop(void) {
- init();
- while (1) {
- enum request_type req = wait_for_requests();
- switch (req) {
- case spawn_channel: break;
- case get_channels: break;
- }
+ signal.sa_handler = exit_tcp;
+ if (sigaction(SIGTERM, &signal, NULL) != 0) {
+ WHERE;
+ exit(EXIT_FAILURE);
}
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
- thread_loop();
+ setup_signal();
+ tcp_loop();
return 0;
}