jitterbug/main.c

56 lines
1.2 KiB
C
Raw Normal View History

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "server.h"
// https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function#FNV-1a_hash
uint64_t hashmap_hash(const char *bytes, size_t bytes_n, size_t map_len)
{
uint64_t hash = 0xcbf29ce484222325;
for (size_t i = 0; i < bytes_n; i++) {
hash *= 0x100000001b3;
hash ^= bytes[i];
}
return (hash % map_len);
}
const char *arg_shift(int *argc, char ***argv) {
if (*argc < 1)
return NULL;
const char *result = *argv[0];
*argc -= 1;
*argv += 1;
return result;
}
int main(int argc, char *argv[])
{
arg_shift(&argc, &argv);
const char *socket_path = arg_shift(&argc, &argv);
socket_path = socket_path == NULL ? "/tmp/jitterbug-unix0" : socket_path;
struct jb_server *srv = jb_server_create(socket_path);
if (srv == NULL) {
fprintf(stderr, "server_create failed\n");
return EXIT_FAILURE;
}
printf("Listening on %s\n", socket_path);
while (1) {
if (jb_server_turn(srv) < 0) {
fprintf(stderr, "server_turn failed\n");
jb_server_free(srv);
return EXIT_FAILURE;
}
}
jb_server_free(srv);
return EXIT_SUCCESS;
}