]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: ISC |
8429abe0 RW |
2 | /* $OpenBSD$ */ |
3 | ||
4 | /* | |
5 | * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> | |
6 | * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org> | |
7 | * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> | |
8429abe0 RW |
8 | */ |
9 | ||
10 | #ifndef _IMSG_H_ | |
11 | #define _IMSG_H_ | |
12 | ||
5e244469 RW |
13 | #ifdef __cplusplus |
14 | extern "C" { | |
15 | #endif | |
16 | ||
8429abe0 RW |
17 | #define IBUF_READ_SIZE 65535 |
18 | #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) | |
19 | #define MAX_IMSGSIZE 16384 | |
20 | ||
21 | struct ibuf { | |
996c9314 | 22 | TAILQ_ENTRY(ibuf) entry; |
d7c0a89a | 23 | uint8_t *buf; |
996c9314 LB |
24 | size_t size; |
25 | size_t max; | |
26 | size_t wpos; | |
27 | size_t rpos; | |
28 | int fd; | |
8429abe0 RW |
29 | }; |
30 | ||
31 | struct msgbuf { | |
996c9314 | 32 | TAILQ_HEAD(, ibuf) bufs; |
d7c0a89a | 33 | uint32_t queued; |
996c9314 | 34 | int fd; |
8429abe0 RW |
35 | }; |
36 | ||
37 | struct ibuf_read { | |
d7c0a89a QY |
38 | uint8_t buf[IBUF_READ_SIZE]; |
39 | uint8_t *rptr; | |
996c9314 | 40 | size_t wpos; |
8429abe0 RW |
41 | }; |
42 | ||
43 | struct imsg_fd { | |
996c9314 LB |
44 | TAILQ_ENTRY(imsg_fd) entry; |
45 | int fd; | |
8429abe0 RW |
46 | }; |
47 | ||
48 | struct imsgbuf { | |
996c9314 LB |
49 | TAILQ_HEAD(, imsg_fd) fds; |
50 | struct ibuf_read r; | |
51 | struct msgbuf w; | |
52 | int fd; | |
53 | pid_t pid; | |
8429abe0 RW |
54 | }; |
55 | ||
56 | #define IMSGF_HASFD 1 | |
57 | ||
58 | struct imsg_hdr { | |
d7c0a89a QY |
59 | uint32_t type; |
60 | uint16_t len; | |
61 | uint16_t flags; | |
62 | uint32_t peerid; | |
63 | uint32_t pid; | |
8429abe0 RW |
64 | }; |
65 | ||
66 | struct imsg { | |
996c9314 LB |
67 | struct imsg_hdr hdr; |
68 | int fd; | |
69 | void *data; | |
8429abe0 RW |
70 | }; |
71 | ||
72 | ||
73 | /* buffer.c */ | |
996c9314 LB |
74 | struct ibuf *ibuf_open(size_t); |
75 | struct ibuf *ibuf_dynamic(size_t, size_t); | |
76 | int ibuf_add(struct ibuf *, const void *, size_t); | |
77 | void *ibuf_reserve(struct ibuf *, size_t); | |
78 | void *ibuf_seek(struct ibuf *, size_t, size_t); | |
79 | size_t ibuf_size(struct ibuf *); | |
80 | size_t ibuf_left(struct ibuf *); | |
81 | void ibuf_close(struct msgbuf *, struct ibuf *); | |
82 | int ibuf_write(struct msgbuf *); | |
83 | void ibuf_free(struct ibuf *); | |
84 | void msgbuf_init(struct msgbuf *); | |
85 | void msgbuf_clear(struct msgbuf *); | |
86 | int msgbuf_write(struct msgbuf *); | |
87 | void msgbuf_drain(struct msgbuf *, size_t); | |
8429abe0 RW |
88 | |
89 | /* imsg.c */ | |
996c9314 LB |
90 | void imsg_init(struct imsgbuf *, int); |
91 | ssize_t imsg_read(struct imsgbuf *); | |
92 | ssize_t imsg_get(struct imsgbuf *, struct imsg *); | |
d7c0a89a QY |
93 | int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const void *, |
94 | uint16_t); | |
95 | int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, | |
996c9314 | 96 | const struct iovec *, int); |
d7c0a89a QY |
97 | struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t); |
98 | int imsg_add(struct ibuf *, const void *, uint16_t); | |
996c9314 LB |
99 | void imsg_close(struct imsgbuf *, struct ibuf *); |
100 | void imsg_free(struct imsg *); | |
101 | int imsg_flush(struct imsgbuf *); | |
102 | void imsg_clear(struct imsgbuf *); | |
8429abe0 | 103 | |
5e244469 RW |
104 | #ifdef __cplusplus |
105 | } | |
106 | #endif | |
107 | ||
8429abe0 | 108 | #endif |