summaryrefslogtreecommitdiff
path: root/cethcan/osc.c
blob: cd957f0e9620cd1834140e442e86df5537ac40d4 (plain)
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
#include "cethcan.h"

struct osc_server *osc_server = NULL;
static struct event *osc_server_event = NULL;

static void osc_sock_handler(int sock, short event, void *arg)
{
	if (osc_server_run(osc_server)) {
		event_del(osc_server_event);
		osc_server_event = NULL;
	}
}

void osc_init(void)
{
	if (osc_server)
		return;

	osc_server = osc_server_new(NULL, "4223", NULL);
	if (!osc_server)
		return;

	if (osc_server_set_blocking(osc_server, false))
		return;

	osc_server_event = event_new(ev_base, osc_server_fd(osc_server),
	                             EV_READ | EV_PERSIST, osc_sock_handler, NULL);
	event_add(osc_server_event, NULL);
}