1 /* $OpenBSD: imsg.h,v 1.7 2023/06/19 17:19:50 claudio Exp $ */
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>
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.
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.
26 #define IBUF_READ_SIZE 65535
27 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
28 #define MAX_IMSGSIZE 16384
31 TAILQ_ENTRY(ibuf
) entry
;
41 TAILQ_HEAD(, ibuf
) bufs
;
47 unsigned char buf
[IBUF_READ_SIZE
];
53 TAILQ_ENTRY(imsg_fd
) entry
;
58 TAILQ_HEAD(, imsg_fd
) fds
;
84 struct ibuf
*ibuf_open(size_t);
85 struct ibuf
*ibuf_dynamic(size_t, size_t);
86 int ibuf_add(struct ibuf
*, const void *, size_t);
87 int ibuf_add_buf(struct ibuf
*, const struct ibuf
*);
88 int ibuf_add_zero(struct ibuf
*, size_t);
89 int ibuf_add_n8(struct ibuf
*, uint64_t);
90 int ibuf_add_n16(struct ibuf
*, uint64_t);
91 int ibuf_add_n32(struct ibuf
*, uint64_t);
92 int ibuf_add_n64(struct ibuf
*, uint64_t);
93 void *ibuf_reserve(struct ibuf
*, size_t);
94 void *ibuf_seek(struct ibuf
*, size_t, size_t);
95 int ibuf_set(struct ibuf
*, size_t, const void *, size_t);
96 int ibuf_set_n8(struct ibuf
*, size_t, uint64_t);
97 int ibuf_set_n16(struct ibuf
*, size_t, uint64_t);
98 int ibuf_set_n32(struct ibuf
*, size_t, uint64_t);
99 int ibuf_set_n64(struct ibuf
*, size_t, uint64_t);
100 void *ibuf_data(struct ibuf
*);
101 size_t ibuf_size(struct ibuf
*);
102 size_t ibuf_left(struct ibuf
*);
103 void ibuf_close(struct msgbuf
*, struct ibuf
*);
104 void ibuf_free(struct ibuf
*);
105 int ibuf_fd_avail(struct ibuf
*);
106 int ibuf_fd_get(struct ibuf
*);
107 void ibuf_fd_set(struct ibuf
*, int);
108 int ibuf_write(struct msgbuf
*);
109 void msgbuf_init(struct msgbuf
*);
110 void msgbuf_clear(struct msgbuf
*);
111 int msgbuf_write(struct msgbuf
*);
114 void imsg_init(struct imsgbuf
*, int);
115 ssize_t
imsg_read(struct imsgbuf
*);
116 ssize_t
imsg_get(struct imsgbuf
*, struct imsg
*);
117 int imsg_compose(struct imsgbuf
*, uint32_t, uint32_t, pid_t
, int,
118 const void *, uint16_t);
119 int imsg_composev(struct imsgbuf
*, uint32_t, uint32_t, pid_t
, int,
120 const struct iovec
*, int);
121 int imsg_compose_ibuf(struct imsgbuf
*, uint32_t, uint32_t, pid_t
,
123 struct ibuf
*imsg_create(struct imsgbuf
*, uint32_t, uint32_t, pid_t
, uint16_t);
124 int imsg_add(struct ibuf
*, const void *, uint16_t);
125 void imsg_close(struct imsgbuf
*, struct ibuf
*);
126 void imsg_free(struct imsg
*);
127 int imsg_flush(struct imsgbuf
*);
128 void imsg_clear(struct imsgbuf
*);