summaryrefslogtreecommitdiff
path: root/main.h
blob: 255a252a402bdc14a09a2b53187de410018c0263 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef foomainhfoo
#define foomainhfoo

#include <sys/socket.h>
#include <netinet/ip.h>

struct cfg;

#include "utils.h"

extern bool exiting;

extern unsigned debug_mask;

enum debug_category {
	DBG_ERROR	= (0x1 << 1),
	DBG_INFO	= (0x1 << 2),
	DBG_VERBOSE	= (0x1 << 3),
	DBG_CFG		= (0x1 << 4),
	DBG_REF		= (0x1 << 5),
	DBG_MALLOC	= (0x1 << 6),
};

static inline bool
debug_enabled(enum debug_category category)
{
	return !!(category & debug_mask);
}

void do_debug(enum debug_category category, const char *fmt, ...);

#define __debug(c, ...) do { if (debug_enabled((c))) do_debug((c), __VA_ARGS__); } while (0)
#define debug(c, fmt, ...) __debug(c, "%s:" fmt, __func__, __VA_ARGS__)
#define verbose(...) __debug(DBG_VERBOSE, __VA_ARGS__)
#define info(...) __debug(DBG_ERROR, __VA_ARGS__)
#define error(...) __debug(DBG_ERROR, __VA_ARGS__)

void die(const char *fmt, ...);

#define perrordie(msg) die("%s: %m\n", msg)

struct uring_task;

/* To save typing in all the function definitions below */
typedef void (*callback_t)(struct cfg *, struct uring_task *, int res);
typedef int (*rcallback_t)(struct cfg *, struct uring_task *, int res);

struct uring_task_buf {
	char buf[4096];
	size_t len;
	size_t done;
	struct iovec iov;
	struct msghdr msg;
};

struct uring_task {
	const char *name;
	unsigned refcount;
	int fd;
	struct uring_task *parent;
	void (*free)(struct uring_task *);
	bool dead;
	struct uring_task_buf *tbuf;
	callback_t callback;
	rcallback_t complete_callback; /* to check if tbuf processing is done */
	callback_t final_callback; /* once tbuf processing is done */
	struct sockaddr_in46 addr; /* used for recvmsg/sendmsg */
	void *priv;
};

struct cfg {
	const char *homedir;
	struct uring_ev *uev;
	struct inotify_ev *iev;
	struct signalfd_ev *sev;
	struct announce *aev;
	struct igmp *igmp;
	struct sd_bus *sd_bus;
	bool sd_bus_failed;
	struct uring_task task;
	struct list_head servers;
};

#endif