Root/fakefile/comm.h

Source at commit 51106cf9b34d773e72aa00385c80a9abb76b28df created 5 years 11 months ago.
By Werner Almesberger, ircstat/ML: update for 11/2013
1/*
2 * comm.h - Fakefile IPC functions
3 *
4 * Copyright 2012 by Werner Almesberger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef COMM_H
13#define COMM_H
14
15#include <sys/types.h>
16
17
18#define FAKEFILE_MASTER_OUT_VAR "FAKEFILE_MASTER_OUT"
19#define FAKEFILE_MASTER_IN_VAR "FAKEFILE_MASTER_IN"
20
21
22struct fakefile_peer;
23struct fakefile_msg;
24
25struct fakefile_peer *fakefile_peer(int in, int out);
26void fakefile_peer_close(struct fakefile_peer *peer);
27int fakefile_peer_fd(const struct fakefile_peer *peer);
28
29struct fakefile_msg *fakefile_msg_new(struct fakefile_peer *peer,
30    int size);
31struct fakefile_msg *fakefile_msg_recv(struct fakefile_peer *peer);
32void fakefile_msg_end(struct fakefile_msg *msg);
33
34void fakefile_msg_add(struct fakefile_msg *msg, const void *buf, size_t len);
35void fakefile_msg_get(struct fakefile_msg *msg, void *buf, size_t len);
36
37
38#define decl_add(type) \
39    static inline void fakefile_msg_add_##type( \
40        struct fakefile_msg *msg, type value) \
41    { \
42        fakefile_msg_add(msg, &value, sizeof(value)); \
43    }
44
45#define decl_get(type) \
46    static inline type fakefile_msg_get_##type( \
47        struct fakefile_msg *msg) \
48    { \
49        type value; \
50                                \
51        fakefile_msg_get(msg, &value, sizeof(value)); \
52        return value; \
53    }
54
55#define decl_access(type) decl_add(type) decl_get(type)
56
57decl_access(int)
58decl_access(size_t)
59decl_access(ssize_t)
60
61#undef decl_add
62#undef decl_get
63#undef decl_access
64
65#endif /* !COMM_H */
66

Archive Download this file

Branches:
master



interactive