aboutsummaryrefslogtreecommitdiff
path: root/src/server/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/main.c')
-rw-r--r--src/server/main.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/server/main.c b/src/server/main.c
new file mode 100644
index 0000000..c92eb75
--- /dev/null
+++ b/src/server/main.c
@@ -0,0 +1,78 @@
+#ifndef _POXIS_C_SOURCE
+#define _POSIX_C_SOURCE 200809L // enable POSIX.1-2017
+#endif
+
+#include <os/os.h>
+#include <basic/basic.h>
+#include <basic/arena.h>
+#include <basic/string32.h>
+#include <server/client_connections.h>
+
+#include <stdio.h>
+#include <string.h>
+
+
+typedef struct {
+ u16 port;
+} ParsedArgs;
+
+
+internal_fn b32
+parse_args(ParsedArgs *args, int argc, char **argv)
+{
+ if (argc != 3) {
+ goto format_err;
+ }
+
+
+ if (strcmp(argv[1], "-port") != 0) {
+ goto format_err;
+ }
+
+ u16 port = atoi(argv[2]);
+ if (port == 0) {
+ printf("port number is invalid\n");
+ return false;
+ }
+
+
+ args->port = port;
+ return true;
+
+
+format_err:
+ printf("invocation format error, execpting \"-port <portnum>\"\n");
+ return false;
+}
+
+
+int
+main(int argc, char **argv)
+{
+ u64 perma_storage_size = MEBIBYTES(2);
+ OSMemory memory;
+ if (!os_memory_allocate(&memory, perma_storage_size)) {
+ return EXIT_FAILURE;
+ }
+
+
+ Arena perma_arena;
+ perma_arena.size_used = 0;
+ perma_arena.size_max = MEBIBYTES(2);
+ perma_arena.memory = memory.p;
+
+
+ ParsedArgs args;
+ if (!parse_args(&args, argc, argv)) {
+ return EXIT_FAILURE;
+ }
+
+ ClientConnections *client_connections = client_connections_create(&perma_arena, args.port);
+ if (!client_connections) {
+ return EXIT_FAILURE;
+ }
+ client_connections_manage(client_connections);
+
+
+ return EXIT_SUCCESS;
+}