aboutsummaryrefslogtreecommitdiffstats
path: root/server/main.c
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov2070@gmail.com>2024-06-21 18:49:43 +0300
committerjustanothercatgirl <sotov2070@gmail.com>2024-06-21 18:55:09 +0300
commitb0af12b287a7c7e3cc5ba39869835126e700f792 (patch)
tree5cc3e225fc4022e4a5a99d5a3c318396f183398d /server/main.c
initial commit
TODO: implement O_NONBLOCK switching on channel socket
Diffstat (limited to 'server/main.c')
-rw-r--r--server/main.c62
1 files changed, 62 insertions, 0 deletions
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 <netinet/in.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+
+#define CONTAINER_IMPLEMENTATION
+#include <container.h>
+#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;
+}