001
2017-10-04
pjp
/* $OpenBSD: imsg.h,v 1.3 2013/12/26 17:32:33 eric Exp $ */
004
2017-10-04
pjp
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
005
2017-10-04
pjp
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
006
2017-10-04
pjp
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
008
2017-10-04
pjp
* Permission to use, copy, modify, and distribute this software for any
009
2017-10-04
pjp
* purpose with or without fee is hereby granted, provided that the above
010
2017-10-04
pjp
* copyright notice and this permission notice appear in all copies.
012
2017-10-04
pjp
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
013
2017-10-04
pjp
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
014
2017-10-04
pjp
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
015
2017-10-04
pjp
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
016
2017-10-04
pjp
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
017
2017-10-04
pjp
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
018
2017-10-04
pjp
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
021
2017-10-04
pjp
#ifndef _IMSG_H_
022
2017-10-04
pjp
#define _IMSG_H_
024
2017-10-04
pjp
#ifndef IOV_MAX
025
2017-10-04
pjp
# if defined(_XOPEN_IOV_MAX)
026
2017-10-04
pjp
# define IOV_MAX _XOPEN_IOV_MAX
027
2017-10-04
pjp
# elif defined(DEF_IOV_MAX)
028
2017-10-04
pjp
# define IOV_MAX DEF_IOV_MAX
030
2017-10-04
pjp
# define IOV_MAX 16
035
2017-10-04
pjp
#define IBUF_READ_SIZE 65535
036
2017-10-04
pjp
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
037
2017-10-04
pjp
#define MAX_IMSGSIZE 16384
039
2017-10-04
pjp
struct ibuf {
040
2017-10-04
pjp
TAILQ_ENTRY(ibuf) entry;
041
2017-10-04
pjp
u_char *buf;
042
2017-10-04
pjp
size_t size;
043
2017-10-04
pjp
size_t max;
044
2017-10-04
pjp
size_t wpos;
045
2017-10-04
pjp
size_t rpos;
049
2017-10-04
pjp
struct msgbuf {
050
2017-10-04
pjp
TAILQ_HEAD(, ibuf) bufs;
051
2017-10-04
pjp
u_int32_t queued;
055
2017-10-04
pjp
struct ibuf_read {
056
2017-10-04
pjp
u_char buf[IBUF_READ_SIZE];
057
2017-10-04
pjp
u_char *rptr;
058
2017-10-04
pjp
size_t wpos;
061
2017-10-04
pjp
struct imsg_fd {
062
2017-10-04
pjp
TAILQ_ENTRY(imsg_fd) entry;
066
2017-10-04
pjp
struct imsgbuf {
067
2017-10-04
pjp
TAILQ_HEAD(, imsg_fd) fds;
068
2017-10-04
pjp
struct ibuf_read r;
069
2017-10-04
pjp
struct msgbuf w;
071
2017-10-04
pjp
pid_t pid;
074
2017-10-04
pjp
#define IMSGF_HASFD 1
076
2017-10-04
pjp
struct imsg_hdr {
077
2017-10-04
pjp
u_int32_t type;
078
2017-10-04
pjp
u_int16_t len;
079
2017-10-04
pjp
u_int16_t flags;
080
2017-10-04
pjp
u_int32_t peerid;
081
2017-10-04
pjp
u_int32_t pid;
084
2017-10-04
pjp
struct imsg {
085
2017-10-04
pjp
struct imsg_hdr hdr;
087
2017-10-04
pjp
void *data;
091
2017-10-04
pjp
/* buffer.c */
092
2017-10-04
pjp
struct ibuf *ibuf_open(size_t);
093
2017-10-04
pjp
struct ibuf *ibuf_dynamic(size_t, size_t);
094
2017-10-04
pjp
int ibuf_add(struct ibuf *, const void *, size_t);
095
2017-10-04
pjp
void *ibuf_reserve(struct ibuf *, size_t);
096
2017-10-04
pjp
void *ibuf_seek(struct ibuf *, size_t, size_t);
097
2017-10-04
pjp
size_t ibuf_size(struct ibuf *);
098
2017-10-04
pjp
size_t ibuf_left(struct ibuf *);
099
2017-10-04
pjp
void ibuf_close(struct msgbuf *, struct ibuf *);
100
2017-10-04
pjp
int ibuf_write(struct msgbuf *);
101
2017-10-04
pjp
void ibuf_free(struct ibuf *);
102
2017-10-04
pjp
void msgbuf_init(struct msgbuf *);
103
2017-10-04
pjp
void msgbuf_clear(struct msgbuf *);
104
2017-10-04
pjp
int msgbuf_write(struct msgbuf *);
105
2017-10-04
pjp
void msgbuf_drain(struct msgbuf *, size_t);
107
2017-10-04
pjp
/* imsg.c */
108
2017-10-04
pjp
int available_fds(unsigned int);
109
2017-10-04
pjp
void imsg_init(struct imsgbuf *, int);
110
2017-10-04
pjp
ssize_t imsg_read(struct imsgbuf *);
111
2017-10-04
pjp
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
112
2017-10-04
pjp
int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
113
2017-10-04
pjp
int, const void *, u_int16_t);
114
2017-10-04
pjp
int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
115
2017-10-04
pjp
int, const struct iovec *, int);
116
2017-10-04
pjp
struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
117
2017-10-04
pjp
u_int16_t);
118
2017-10-04
pjp
int imsg_add(struct ibuf *, const void *, u_int16_t);
119
2017-10-04
pjp
void imsg_close(struct imsgbuf *, struct ibuf *);
120
2017-10-04
pjp
void imsg_free(struct imsg *);
121
2017-10-04
pjp
int imsg_flush(struct imsgbuf *);
122
2017-10-04
pjp
void imsg_clear(struct imsgbuf *);