]>
Commit | Line | Data |
---|---|---|
8429abe0 RW |
1 | /* $OpenBSD$ */ |
2 | ||
3 | /* | |
4 | * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> | |
5 | * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org> | |
6 | * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> | |
7 | * | |
8 | * Permission to use, copy, modify, and distribute this software for any | |
9 | * purpose with or without fee is hereby granted, provided that the above | |
10 | * copyright notice and this permission notice appear in all copies. | |
11 | * | |
12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
19 | */ | |
20 | ||
21 | #ifndef _IMSG_H_ | |
22 | #define _IMSG_H_ | |
23 | ||
5e244469 RW |
24 | #ifdef __cplusplus |
25 | extern "C" { | |
26 | #endif | |
27 | ||
8429abe0 RW |
28 | #define IBUF_READ_SIZE 65535 |
29 | #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) | |
30 | #define MAX_IMSGSIZE 16384 | |
31 | ||
32 | struct ibuf { | |
996c9314 | 33 | TAILQ_ENTRY(ibuf) entry; |
d7c0a89a | 34 | uint8_t *buf; |
996c9314 LB |
35 | size_t size; |
36 | size_t max; | |
37 | size_t wpos; | |
38 | size_t rpos; | |
39 | int fd; | |
8429abe0 RW |
40 | }; |
41 | ||
42 | struct msgbuf { | |
996c9314 | 43 | TAILQ_HEAD(, ibuf) bufs; |
d7c0a89a | 44 | uint32_t queued; |
996c9314 | 45 | int fd; |
8429abe0 RW |
46 | }; |
47 | ||
48 | struct ibuf_read { | |
d7c0a89a QY |
49 | uint8_t buf[IBUF_READ_SIZE]; |
50 | uint8_t *rptr; | |
996c9314 | 51 | size_t wpos; |
8429abe0 RW |
52 | }; |
53 | ||
54 | struct imsg_fd { | |
996c9314 LB |
55 | TAILQ_ENTRY(imsg_fd) entry; |
56 | int fd; | |
8429abe0 RW |
57 | }; |
58 | ||
59 | struct imsgbuf { | |
996c9314 LB |
60 | TAILQ_HEAD(, imsg_fd) fds; |
61 | struct ibuf_read r; | |
62 | struct msgbuf w; | |
63 | int fd; | |
64 | pid_t pid; | |
8429abe0 RW |
65 | }; |
66 | ||
67 | #define IMSGF_HASFD 1 | |
68 | ||
69 | struct imsg_hdr { | |
d7c0a89a QY |
70 | uint32_t type; |
71 | uint16_t len; | |
72 | uint16_t flags; | |
73 | uint32_t peerid; | |
74 | uint32_t pid; | |
8429abe0 RW |
75 | }; |
76 | ||
77 | struct imsg { | |
996c9314 LB |
78 | struct imsg_hdr hdr; |
79 | int fd; | |
80 | void *data; | |
8429abe0 RW |
81 | }; |
82 | ||
83 | ||
84 | /* buffer.c */ | |
996c9314 LB |
85 | struct ibuf *ibuf_open(size_t); |
86 | struct ibuf *ibuf_dynamic(size_t, size_t); | |
87 | int ibuf_add(struct ibuf *, const void *, size_t); | |
88 | void *ibuf_reserve(struct ibuf *, size_t); | |
89 | void *ibuf_seek(struct ibuf *, size_t, size_t); | |
90 | size_t ibuf_size(struct ibuf *); | |
91 | size_t ibuf_left(struct ibuf *); | |
92 | void ibuf_close(struct msgbuf *, struct ibuf *); | |
93 | int ibuf_write(struct msgbuf *); | |
94 | void ibuf_free(struct ibuf *); | |
95 | void msgbuf_init(struct msgbuf *); | |
96 | void msgbuf_clear(struct msgbuf *); | |
97 | int msgbuf_write(struct msgbuf *); | |
98 | void msgbuf_drain(struct msgbuf *, size_t); | |
8429abe0 RW |
99 | |
100 | /* imsg.c */ | |
996c9314 LB |
101 | void imsg_init(struct imsgbuf *, int); |
102 | ssize_t imsg_read(struct imsgbuf *); | |
103 | ssize_t imsg_get(struct imsgbuf *, struct imsg *); | |
d7c0a89a QY |
104 | int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const void *, |
105 | uint16_t); | |
106 | int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, | |
996c9314 | 107 | const struct iovec *, int); |
d7c0a89a QY |
108 | struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t); |
109 | int imsg_add(struct ibuf *, const void *, uint16_t); | |
996c9314 LB |
110 | void imsg_close(struct imsgbuf *, struct ibuf *); |
111 | void imsg_free(struct imsg *); | |
112 | int imsg_flush(struct imsgbuf *); | |
113 | void imsg_clear(struct imsgbuf *); | |
8429abe0 | 114 | |
5e244469 RW |
115 | #ifdef __cplusplus |
116 | } | |
117 | #endif | |
118 | ||
8429abe0 | 119 | #endif |