Annotation of src/usr.bin/tmux/imsg.h, Revision 1.4
1.4 ! nicm 1: /* $OpenBSD: imsg.h,v 1.5 2010/04/27 21:04:04 nicm Exp $ */
1.1 nicm 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:
1.4 ! nicm 21: #define IBUF_READ_SIZE 65535
1.1 nicm 22: #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
23: #define MAX_IMSGSIZE 16384
24:
1.4 ! nicm 25: struct ibuf {
! 26: TAILQ_ENTRY(ibuf) entry;
1.1 nicm 27: u_char *buf;
28: size_t size;
29: size_t max;
30: size_t wpos;
31: size_t rpos;
32: int fd;
33: };
34:
35: struct msgbuf {
1.4 ! nicm 36: TAILQ_HEAD(, ibuf) bufs;
1.1 nicm 37: u_int32_t queued;
38: int fd;
39: };
40:
1.4 ! nicm 41: struct ibuf_read {
! 42: u_char buf[IBUF_READ_SIZE];
1.1 nicm 43: u_char *rptr;
44: size_t wpos;
45: };
46:
47: struct imsg_fd {
48: TAILQ_ENTRY(imsg_fd) entry;
49: int fd;
50: };
51:
52: struct imsgbuf {
53: TAILQ_HEAD(, imsg_fd) fds;
1.4 ! nicm 54: struct ibuf_read r;
1.1 nicm 55: struct msgbuf w;
56: int fd;
57: pid_t pid;
58: };
59:
60: #define IMSGF_HASFD 1
61:
62: struct imsg_hdr {
63: u_int32_t type;
64: u_int16_t len;
65: u_int16_t flags;
66: u_int32_t peerid;
67: u_int32_t pid;
68: };
69:
70: struct imsg {
71: struct imsg_hdr hdr;
72: int fd;
73: void *data;
74: };
75:
76:
77: /* buffer.c */
1.4 ! nicm 78: struct ibuf *ibuf_open(size_t);
! 79: struct ibuf *ibuf_dynamic(size_t, size_t);
! 80: int ibuf_add(struct ibuf *, const void *, size_t);
! 81: void *ibuf_reserve(struct ibuf *, size_t);
! 82: void *ibuf_seek(struct ibuf *, size_t, size_t);
! 83: size_t ibuf_size(struct ibuf *);
! 84: size_t ibuf_left(struct ibuf *);
! 85: void ibuf_close(struct msgbuf *, struct ibuf *);
! 86: int ibuf_write(struct msgbuf *);
! 87: void ibuf_free(struct ibuf *);
1.1 nicm 88: void msgbuf_init(struct msgbuf *);
89: void msgbuf_clear(struct msgbuf *);
90: int msgbuf_write(struct msgbuf *);
1.2 jacekm 91: void msgbuf_drain(struct msgbuf *, size_t);
1.1 nicm 92:
93: /* imsg.c */
94: void imsg_init(struct imsgbuf *, int);
95: ssize_t imsg_read(struct imsgbuf *);
96: ssize_t imsg_get(struct imsgbuf *, struct imsg *);
97: int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
98: int, void *, u_int16_t);
99: int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
100: int, const struct iovec *, int);
1.4 ! nicm 101: struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t,
1.1 nicm 102: u_int16_t);
1.4 ! nicm 103: int imsg_add(struct ibuf *, void *, u_int16_t);
! 104: void imsg_close(struct imsgbuf *, struct ibuf *);
1.1 nicm 105: void imsg_free(struct imsg *);
106: int imsg_flush(struct imsgbuf *);
107: void imsg_clear(struct imsgbuf *);