aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/server.c
blob: 3e9f080f761c35e7773bcf7ee893fd13bd4d9306 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "server.h"
#include "msg.h"
#include "net.h"
#include "tcp_server.h"

#include <stdio.h>
#include <unistd.h>

int server_create(struct server *server, const struct settings *settings)
{
	int ret = 0;

	ret = tcp_server_create(&server->tcp_server, settings->port);
	if (ret < 0)
		return ret;

	return 0;
}

void server_destroy(const struct server *server)
{
	tcp_server_destroy(&server->tcp_server);
}

static int server_msg_handler(const struct msg *msg, void *)
{
	return msg_dump_unknown(msg);
}

static int server_conn_handler(int fd, void *)
{
	return msg_recv_and_handle(fd, server_msg_handler, NULL);
}

int server_main(const struct server *server)
{
	int ret = 0;

	while (1) {
		ret = tcp_server_accept(&server->tcp_server, server_conn_handler, NULL);
		if (ret < 0)
			return ret;
	}
}