chiark / gitweb /
process: Introduce afterfork()
[secnet.git] / comm-common.c
1
2 #include "secnet.h"
3 #include "comm-common.h"
4
5 void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn)
6 {
7     struct commcommon *st=commst;
8     struct comm_notify_entry *n;
9     
10     n=safe_malloc(sizeof(*n),"comm_request_notify_core");
11     n->fn=fn;
12     n->state=nst;
13     n->fn=fn;
14     n->state=nst;
15     LIST_INSERT_HEAD(&st->notify, n, entry);
16 }
17
18 void comm_release_notify(void *commst, void *nst, comm_notify_fn *fn)
19 {
20     struct commcommon *st=commst;
21     struct comm_notify_entry *n, *t;
22
23     /* XXX untested */
24     LIST_FOREACH_SAFE(n, &st->notify, entry, t) {
25        if (n->state==nst && n->fn==fn) {
26            LIST_REMOVE(n, entry);
27            free(n);
28        }
29     }
30 }
31
32 bool_t comm_notify(struct comm_notify_list *notify,
33                    struct buffer_if *buf, const struct comm_addr *ca)
34 {
35     struct comm_notify_entry *n;
36
37     LIST_FOREACH(n, notify, entry) {
38         if (n->fn(n->state, buf, ca)) {
39             return True;
40         }
41     }
42     return False;
43 }
44
45 void comm_apply(struct commcommon *cc)
46 {
47     cc->cl.type=CL_COMM;
48     cc->cl.apply=NULL;
49     cc->cl.interface=&cc->ops;
50     cc->ops.st=cc;
51     cc->ops.request_notify=comm_request_notify;
52     cc->ops.release_notify=comm_release_notify;
53     LIST_INIT(&cc->notify);
54     cc->rbuf=NULL;
55 }