jitterbug/main.c

45 lines
1,005 B
C
Raw Normal View History

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
2022-12-26 20:28:56 +02:00
#include <string.h>
#include <errno.h>
#include "server.h"
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) {
2022-12-26 20:28:56 +02:00
fprintf(stderr, "server_turn failed (errno=%d, strerror=%s)\n", errno, strerror(errno));
jb_server_free(srv);
return EXIT_FAILURE;
}
}
jb_server_free(srv);
return EXIT_SUCCESS;
}