From b0af12b287a7c7e3cc5ba39869835126e700f792 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Fri, 21 Jun 2024 18:49:43 +0300 Subject: initial commit TODO: implement O_NONBLOCK switching on channel socket --- server/main.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 server/main.c (limited to 'server/main.c') diff --git a/server/main.c b/server/main.c new file mode 100644 index 0000000..f899f7e --- /dev/null +++ b/server/main.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include + +#define CONTAINER_IMPLEMENTATION +#include +#undef CONTAINER_IMPLEMENTATION + +#include "channel.h" + +#define MAIN_PORT 8164 + +enum request_type { + spawn_channel, + get_channels, +}; + +static int* open_sockets; +static int request_socket; + +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); + } + } +} + +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; + } + } +} + +int main(int argc, char *argv[]) { + (void)argc; + (void)argv; + thread_loop(); + return 0; +} -- cgit v1.2.3-70-g09d2