-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipc.c
71 lines (57 loc) · 1.04 KB
/
ipc.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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include "mcc.h"
#include "network.h"
#include "socket.h"
struct ipc_t
{
int fd;
};
static void ipc_run(int fd, bool can_write, bool can_read, void *arg)
{
struct ipc_t *ipc = arg;
}
static void ipc_init(struct ipc_t *ipc)
{
struct sockaddr_un saun;
ipc->fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (ipc->fd < 0)
{
perror("socket");
return;
}
saun.sun_family = AF_UNIX;
strncpy(saun.sun_path, "/tmp/mccsocket", sizeof saun.sun_path);
if (bind(ipc->fd, (const struct sockaddr *)&saun, sizeof saun) < 0)
{
perror("bind");
return;
}
if (listen(ipc->fd, 0) < 0)
{
perror("listen");
return;
}
register_socket(ipc->fd, &ipc_run, ipc);
}
void module_init(void **arg)
{
struct ipc_t *ipc = malloc(sizeof *ipc);
ipc->fd = -1;
ipc_init(ipc);
*arg = ipc;
}
void module_deinit(void *arg)
{
struct ipc_t *ipc = arg;
if (ipc->fd != -1)
{
close(ipc->fd);
deregister_socket(ipc->fd);
}
free(ipc);
}