imsg.h 3.0 KB

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