-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproc.c
78 lines (63 loc) · 1.43 KB
/
proc.c
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
#define MODULE_NAME "proc"
#include <stdlib.h>
#include <string.h>
#include "util.h"
#include "proc.h"
#include "net.h"
#include "log.h"
#include "clt.h"
#include "srv.h"
struct wqueue_entry
{
int target;
char *data;
size_t datasz;
struct wqueue_entry *next;
};
struct wqueue
{
struct wqueue_entry *head;
struct wqueue_entry *tail;
size_t length;
};
static struct wqueue g_wqueue = {0};
void proc_wqueue_add(int target, const char *data)
{
struct wqueue_entry *e = malloc(sizeof *e);
e->target = target;
e->data = util_strdup(data);
e->datasz = strlen(data);
e->next = NULL;
if(!g_wqueue.head)
g_wqueue.head = g_wqueue.tail = e;
else
g_wqueue.tail->next = e, g_wqueue.tail = e;
g_wqueue.length++;
}
void proc_wqueue_next(void)
{
struct wqueue_entry *t = g_wqueue.head;
g_wqueue.head = g_wqueue.head->next;
g_wqueue.length--;
if(!g_wqueue.head)
g_wqueue.tail = NULL;
free(t->data);
free(t);
}
size_t proc_wqueue_length(void){ return g_wqueue.length; }
wqueue_entry_t proc_wqueue_head(void){ return g_wqueue.head; }
int proc_wqueue_entry_target(wqueue_entry_t d){ return d->target; }
void *proc_wqueue_entry_data(wqueue_entry_t d){ return d->data; }
size_t proc_wqueue_entry_datasz(wqueue_entry_t d){ return d->datasz; }
void proc_tick(void)
{
clt_tick();
}
void proc_proc(int nid, char *msg)
{
if(net_id2fd(nid) == srv_socket())
srv_message_process(msg);
else
clt_message_process(nid, msg);
}
#undef MODULE_NAME